Skip to content

Bug leads to crash program when using .set<T>() and then apply_visitor()  #152

Description

@huanncbg

#include
#include <mapbox/variant.hpp>
#include <unordered_map>
using namespace std;
using namespace mapbox::util;

// Forward declaration
struct HPArray;
struct HPTable;
using HPVariant = variant<string,float,recursive_wrapper>;

struct HPArray{
template <typename ...Args>
HPArray(Args ...args){
values.emplace(std::forward(args)...);
}
unordered_map<int,HPVariant> values;
};

struct Visitor{

void operator()(const string &str){
    cout << str <<endl;;
}

void operator()(const float &value){
    cout << value <<endl;
}

void operator()(HPArray array){
    for (size_t i = 0; i < array.values.size(); i++)
    {
        apply_visitor(*this,array.values[i]);
    }
}

};

int main()
{
HPArray ar;
ar.values[0] = HPVariant("String");
ar.values[1] = 2.0f;

HPVariant var;
var.set<HPArray>(ar);
Visitor visitor;
apply_visitor(visitor,var);
return 0;

}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions