Hi all,
I'm trying to use the recursive variant as following:
typedef boost::make_recursive_variant<
int,
std::vector<boost::recursive_variant_>,
std::map<std::string, boost::recursive_variant_>
>::type var_t;
...
var_t var(34);
...
VC 8.0 can not compile with error C2079: 'std::pair<_Ty1,_Ty2>::second' uses undefined struct 'boost::recursive_variant_'
Struct recursive_variant_ is declared but not implement at all. But GCC works well. I'm confused how to solve the problem.
Here is the whole program:
#include "boost/variant.hpp"
#include <iostream>
#include <sstream>
#include <vector>
#include
<map>
struct vector_printer
: boost::static_visitor<std::string>
{
template <typename T>
std::string operator()(const std::vector<T>& vec) const
{
std::ostringstream ost;
ost << "( ";
typename std::vector<T>::const_iterator it = vec.begin();
for (; it != vec.end(); ++it)
ost << boost::apply_visitor( vector_printer(), *it );
ost << ") ";
return ost.str();
}
template <typename T>
std::string operator()(
const std::map<std::string, T>& m) const
{
std::ostringstream ost;
ost << "( ";
typename std::map<std::string, T>::const_iterator it = m.begin();
for (; it != m.end(); ++it)
ost << it->first <<
'\t' << boost::apply_visitor( vector_printer(), it->second );
ost << ") ";
return ost.str();
}
template <typename T>
std::string operator()(
const T& operand) const
{
std::ostringstream ost;
ost << operand << ' ';
return ost.str();
}
};
int main(int , char* [])
{
typedef
boost::make_recursive_variant<
int,
std::vector<boost::recursive_variant_>,
std::map<std::string, boost::recursive_variant_>
>::type var_t;
std::vector<var_t> vec;
vec.push_back(3);
vec.push_back(5);
vec.push_back(vec);
vec.push_back(7
);
var_t var(vec);
std::string result( boost::apply_visitor( vector_printer(), var ) );
std::cout << "result: " << result <<
'\n';
return 0;
}
And the compile error from VC8 is :
test_map_variant.cpp
D:\Program\boost\boost_1_33_1\boost/type_traits/is_base_and_derived.hpp : warning C4819: The file contains a character that cannot be represented in the current code page (936). Save the file in Unicode format to prevent data loss
D:\Program\boost\boost_1_33_1\boost/utility/enable_if.hpp : warning C4819: The file contains a character that cannot be represented in the current code page (936). Save the file in Unicode format to prevent data loss
D:\Program\boost\boost_1_33_1\boost/type_traits/is_base_and_derived.hpp : warning C4819: The file contains a character that cannot be represented in the current code page (936). Save the file in Unicode format to prevent data loss
D:\Program\boost\boost_1_33_1\boost/utility/enable_if.hpp : warning C4819: The file contains a character that cannot be represented in the current code page (936). Save the file in Unicode format to prevent data loss
D:\Program\boost\boost_1_33_1\boost/utility/enable_if.hpp : warning C4819: The file contains a character that cannot be represented in the current code page (936). Save the file in Unicode format to prevent data loss
D:\Program\vs8\VC\INCLUDE\utility(54) : error C2079: 'std::pair<_Ty1,_Ty2>::second' uses undefined struct 'boost::recursive_variant_'
with
[
_Ty1=const std::string,
_Ty2=boost::recursive_variant_
]
D:\Program\vs8\VC\INCLUDE\vector(1083) : see reference to class template instantiation 'std::pair<_Ty1,_Ty2>' being compiled
with
[
_Ty1=const std::string,
_Ty2=boost::recursive_variant_
]
D:\Program\vs8\VC\INCLUDE\vector(1082) : while compiling class template member function 'void std::vector<_Ty>::_Destroy(boost::variant<T0_,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19> *,boost::variant<T0_,T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16,T17,T18,T19> *)'
with
[
_Ty=var_t,
T0_=boost::detail::variant::recursive_flag<int>,
T1=std::vector<boost::recursive_variant_>,
T2=std::map<std::string,boost::recursive_variant_>,
T3=boost::detail::variant::void_,
T4=boost::detail::variant::void_,
T5=boost::detail::variant::void_,
T6=boost::detail::variant::void_,
T7=boost::detail::variant::void_,
T8=boost::detail::variant::void_,
T9=boost::detail::variant::void_,
T10=boost::detail::variant::void_,
T11=boost::detail::variant::void_,
T12=boost::detail::variant::void_,
T13=boost::detail::variant::void_,
T14=boost::detail::variant::void_,
T15=boost::detail::variant::void_,
T16=boost::detail::variant::void_,
T17=boost::detail::variant::void_,
T18=boost::detail::variant::void_,
T19=boost::detail::variant::void_
]
test_map_variant.cpp(63) : see reference to class template instantiation 'std::vector<_Ty>' being compiled
with
[
_Ty=var_t
]
--
B. R.
Andy