Question

I am decoding bencode, and have some code which works well with gcc 4.4. But having recently upgraded to gcc 4.6 this code no longer builds:

#ifndef BENCODE_VALUETYPES_H
#define BENCODE_VALUETYPES_H

#include <boost/variant.hpp>

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

namespace bencode {

  typedef boost::make_recursive_variant<
    int,
    std::string,
    std::vector<boost::recursive_variant_>,
    std::map<std::string, boost::recursive_variant_> >::type Value;

  typedef std::map<std::string, Value> ValueDictionary;
  typedef std::vector<Value> ValueVector;

};

#endif

g++ gives this error message:

/usr/include/c++/4.6/bits/stl_pair.h: In instantiation of 'std::pair<const std::basic_string<char>, boost::recursive_variant_>':
Decoder.cpp:97:39:   instantiated from here
/usr/include/c++/4.6/bits/stl_pair.h:93:11: error: 'std::pair<_T1, _T2>::second' has incomplete type
/usr/include/boost/variant/variant_fwd.hpp:232:12: error: forward declaration of 'struct boost::recursive_variant_'

The documentation for the latest boost version (1.48 at the moment) states that "due to standard conformance issues in several compilers, make_recursive_variant is not universally supported", and that you should use the recursive_wrapper instead. But I am having problem making the change: does anyone know what this should look like using the wrapper?

Was it helpful?

Solution

Try defining below in your header file before you include boost variant headers.

#define BOOST_VARIANT_NO_FULL_RECURSIVE_VARIANT_SUPPORT
#include <boost/variant.hpp>

I had the same issue and found solution at boost variant recursive

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top