Boost logo

Boost Users :

From: Paul.VanHagen_at_[hidden]
Date: 2007-06-20 07:20:49


Hello,

I'm having difficulty compiling the following code fragment using the Intel 9.1 C++ compiler.

This little program mimics part of our application and the way we make use of the boost::variant class template. The build log follows at the end. The program itself is totally meaningless, but it just demonstrates a problem in either the compiler or in boost.

The strange thing is that this program compiles nicely without any problem using the gcc 3.3.1 compiler on Linux.

I appreciate any help.

TIA

Paul

#include <map>
#include <string>
#include <boost/variant.hpp>

using namespace std;

template <typename IntT=int>
class A
{
  public:
    A() : m_i(0) { }
    A(const IntT& i) : m_i(i) { }
  private:
    IntT m_i;
};

template <typename StringT, typename IntT=int>
class B
{
  public:
    B() : m_pi(0) { }
    B(const string& s, const IntT& i) : m_pi(new IntT(i)) { }
    ~B() { delete m_pi; }
  private:
    StringT m_s;
    IntT* m_pi;
};

typedef A<> a_t;
typedef B<string> b_t;

typedef boost::variant<a_t, boost::recursive_wrapper<b_t> > Integer;
typedef Integer* IntegerPtr;

template <typename CharT, typename IntT, typename DoubleT>
class numeric_type
        : public boost::variant<CharT, IntT*, DoubleT>
{
public:
        typedef boost::variant<CharT, IntT*, DoubleT> numeric_type_variant;
        /// Default constructor.
        numeric_type() : numeric_type_variant() { }

        numeric_type(const CharT& ch) : numeric_type_variant(ch)
        {
        }
        numeric_type(IntT* pInt) : numeric_type_variant(pInt)
        {
        }
        numeric_type(const DoubleT& d) : numeric_type_variant(d)
        {
        }
        /* template <typename T>
        /// Converting constructor.
        numeric_type(T const& t) : numeric_type_variant(t) { } */

        // some more code
};

int main(int argc, char* argv[])
{
        char ba;
        double bc;
        // set up map with variant integers
        map<string, Integer> mapInteger;
        mapInteger.insert(make_pair("a", a_t(0)));
        mapInteger.insert(make_pair("b", b_t("b", 1)));
 
        numeric_type<char, Integer, double> b(ba);
        numeric_type<char, Integer, double> c(&mapInteger["b"]);
        numeric_type<char, Integer, double> d(bc);

        return 0;
}

------ Build started: Project: VariantProblemDemo, Configuration: Debug Win32 ------

Compiling...
VariantProblemDemo.cpp
C:\Mijn Documenten\Backup\Projects\Work\3rdParty\boost\boost\variant\variant.hpp(1273) : error C2668: 'boost::detail::variant::make_initializer_node::apply<BaseIndexPair,Iterator>::initializer_node::initialize' : ambiguous call to overloaded function
        with
        [
            BaseIndexPair=boost::mpl::aux::iter_fold_impl<2,boost::mpl::begin<boost::variant<a_t,boost::recursive_wrapper<b_t>>::recursive_enabled_types>::type,boost::mpl::end<boost::variant<a_t,boost::recursive_wrapper<b_t>>::recursive_enabled_types>::type,boost::mpl::pair<boost::detail::variant::initializer_root,boost::mpl::int_<0>>,boost::mpl::lambda<boost::mpl::protect<boost::detail::variant::make_initializer_node>>::type>::state1,
            Iterator=boost::mpl::aux::iter_fold_impl<2,boost::mpl::begin<boost::variant<a_t,boost::recursive_wrapper<b_t>>::recursive_enabled_types>::type,boost::mpl::end<boost::variant<a_t,boost::recursive_wrapper<b_t>>::recursive_enabled_types>::type,boost::mpl::pair<boost::detail::variant::initializer_root,boost::mpl::int_<0>>,boost::mpl::lambda<boost::mpl::protect<boost::detail::variant::make_initializer_node>>::type>::iter1
        ]
        C:\Mijn Documenten\Backup\Projects\Work\3rdParty\boost\boost\variant\detail\initializer.hpp(89): could be 'int boost::detail::variant::make_initializer_node::apply<BaseIndexPair,Iterator>::initializer_node::initialize(void *,boost::detail::variant::make_initializer_node::apply<BaseIndexPair,Iterator>::initializer_node::param_T)'
        with
        [
            BaseIndexPair=boost::mpl::aux::iter_fold_impl<2,boost::mpl::begin<boost::variant<a_t,boost::recursive_wrapper<b_t>>::recursive_enabled_types>::type,boost::mpl::end<boost::variant<a_t,boost::recursive_wrapper<b_t>>::recursive_enabled_types>::type,boost::mpl::pair<boost::detail::variant::initializer_root,boost::mpl::int_<0>>,boost::mpl::lambda<boost::mpl::protect<boost::detail::variant::make_initializer_node>>::type>::state1,
            Iterator=boost::mpl::aux::iter_fold_impl<2,boost::mpl::begin<boost::variant<a_t,boost::recursive_wrapper<b_t>>::recursive_enabled_types>::type,boost::mpl::end<boost::variant<a_t,boost::recursive_wrapper<b_t>>::recursive_enabled_types>::type,boost::mpl::pair<boost::detail::variant::initializer_root,boost::mpl::int_<0>>,boost::mpl::lambda<boost::mpl::protect<boost::detail::variant::make_initializer_node>>::type>::iter1
        ]
        C:\Mijn Documenten\Backup\Projects\Work\3rdParty\boost\boost\variant\detail\initializer.hpp(89): or 'int boost::detail::variant::make_initializer_node::apply<BaseIndexPair,Iterator>::initializer_node::initialize(void *,boost::detail::variant::make_initializer_node::apply<BaseIndexPair,Iterator>::initializer_node::param_T)'
        with
        [
            BaseIndexPair=boost::mpl::aux::iter_fold_impl<2,boost::mpl::begin<boost::variant<a_t,boost::recursive_wrapper<b_t>>::recursive_enabled_types>::type,boost::mpl::end<boost::variant<a_t,boost::recursive_wrapper<b_t>>::recursive_enabled_types>::type,boost::mpl::pair<boost::detail::variant::initializer_root,boost::mpl::int_<0>>,boost::mpl::lambda<boost::mpl::protect<boost::detail::variant::make_initializer_node>>::type>::state0,
            Iterator=boost::mpl::aux::iter_fold_impl<2,boost::mpl::begin<boost::variant<a_t,boost::recursive_wrapper<b_t>>::recursive_enabled_types>::type,boost::mpl::end<boost::variant<a_t,boost::recursive_wrapper<b_t>>::recursive_enabled_types>::type,boost::mpl::pair<boost::detail::variant::initializer_root,boost::mpl::int_<0>>,boost::mpl::lambda<boost::mpl::protect<boost::detail::variant::make_initializer_node>>::type>::iter0
        ]
        while trying to match the argument list '(void *, const int)'
        C:\Mijn Documenten\Backup\Projects\Work\3rdParty\boost\boost\variant\variant.hpp(1342) : see reference to function template instantiation 'void boost::variant<T0_,T1>::convert_construct<const T>(const T &,int,boost::mpl::false_)' being compiled
        with
        [
            T0_=a_t,
            T1=boost::recursive_wrapper<b_t>,
            T=int
        ]
        VariantProblemDemo.cpp(62) : see reference to function template instantiation 'boost::variant<T0_,T1>::variant<int>(const T &)' being compiled
        with
        [
            T0_=a_t,
            T1=boost::recursive_wrapper<b_t>,
            T=int
        ]

VariantProblemDemo - 1 error(s), 0 warning(s)

---------------------- Done ----------------------

    Build: 0 succeeded, 1 failed, 0 skipped


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net