Hi all,
I'm trying to use the recursive variant as following:
typedef boost::make_recursive_variant<
int,
std::vectorboost::recursive_variant_,
std::map
>::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_visitorstd::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& m) const
{
std::ostringstream ost;
ost << "( ";
typename std::map::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::vectorboost::recursive_variant_,
std::map
>::type var_t;
std::vector 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
*,boost::variant
*)'
with
[
_Ty=var_t,
T0_=boost::detail::variant::recursive_flag<int>,
T1=std::vectorboost::recursive_variant_,
T2=std::mapstd::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