rttrorg / rttr

C++ Reflection Library
https://www.rttr.org
MIT License
3.12k stars 430 forks source link

why failed to set_value for a sequential view ? #278

Open bruceauyeung opened 4 years ago

bruceauyeung commented 4 years ago

registration:

registration::class_<std::vector<char*>>("std::vector<char*>")
    .constructor<std::vector<char*>::size_type>()
    (
        policy::ctor::as_raw_ptr
    ).constructor<std::vector<char*>::size_type, std::vector<char*>::value_type>()
    (
        policy::ctor::as_raw_ptr,
        default_arguments((char *)NULL)
    );

element assignment


type charPtrArray = type::get_by_name("std::vector<char*>");
auto charPtrArrayInst = charPtrArray.create({ size +1 });  // size is size of a_std_map_view
auto charPtrArrayInstView = charPtrArrayInst.create_sequential_view();
char * aa = "123";
if (!charPtrArrayInstView.set_value(0, aa)) {  // OK here
    ofs << "failed to set first elemement value:"  << std::endl;
    ofs.flush();
}
int i = 1;
for (const auto& item : a_std_map_view)
{
    auto addr = item.second.get_wrapped_value<std::string>().c_str();
    if (!charPtrArrayInstView.set_value(i, addr)) { //FAILED here
        ofs << "failed to set array value: " << addr << std::endl;
        ofs.flush();
    }
    i++;
}