C++ (Cpp) variant_array_view Example

Introduction

The c++ (cpp) variant_array_view example is extracted from the most popular open source projects, you can refer to the following example for usage.

Programming language: C++ (Cpp)

Class/type: variant_array_view

Example#1
File: variant_array_view_test.cppProject: The-Futur1st/rttr

#include <rttr/type>

#include <vector>
#include <map>
#include <string>

using namespace rttr;
using namespace std;

/////////////////////////////////////////////////////////////////////////////////////////

TEST_CASE("variant_array_view::ctor", "[variant_array_view]")
{
   SECTION("empty")
   {
        variant_array_view a;
        CHECK(a.is_valid() == false);

        variant_array_view b(a);
        CHECK(b.is_valid() == false);

        variant var;
        variant_array_view c = var.create_array_view();

        CHECK(c.is_valid() == false);
        CHECK(c.is_dynamic() == false);
        CHECK(c.get_rank_type(0).is_valid() == false);
        CHECK(c.get_rank() == 0);
        CHECK(c.get_type().is_valid() == false);
        CHECK(c.get_size() == 0);
        CHECK(c.get_size(0) == 0);

Example#2
File: property_class_invoke_policy.cppProject: respu/rttr

            policy::prop::bind_as_ptr
        )
        ;
}

/////////////////////////////////////////////////////////////////////////////////////////

TEST_CASE("property - class - get/set - bind_as_ptr - array", "[property]")
{
    property_member_policy obj;
    type prop_type = type::get(obj);
    property array_prop = prop_type.get_property("array");

    REQUIRE(array_prop.is_array() == true);
    variant array_obj = array_prop.get_value(obj); // the array is returned by pointer
    variant_array_view vec_array = array_obj.create_array_view();
    REQUIRE(vec_array.is_valid() == true);
    REQUIRE(array_obj.is_type<std::vector<int>*>() == true);
    REQUIRE(array_obj.get_value<std::vector<int>*>() == &obj._array);
}

/////////////////////////////////////////////////////////////////////////////////////////

TEST_CASE("property - class - get/set - bind_as_ptr - raw_array", "[property]")
{
    property_member_policy obj;
    type prop_type = type::get(obj);

    property array_prop = prop_type.get_property("raw_array");
    REQUIRE(array_prop.is_array() == true);
    variant array_obj = array_prop.get_value(obj); // the array is returned by pointer