boost::variant Binary visitation

Discussion in 'C++' started by morten, May 9, 2007.

  1. morten

    morten Guest

    When i compile this code in VC71 or VC80 i get the following errors:
    The code is copy/paste from the boost.org tutorial. Please help!

    error C2039: 'begin' : is not a member of 'boost::variant<T0_,T1>'
    with
    [
    T0_=int,
    T1=std::string
    ]
    Test2.cpp(47): error C2039: 'end' : is not a member of
    'boost::variant<T0_,T1>'
    with
    [
    T0_=int,
    T1=std::string
    ]
    Test2.cpp(47): error C2039: 'begin' : is not a member of
    'boost::variant<T0_,T1>'
    with
    [
    T0_=double,
    T1=std::string
    ]
    "

    #include "boost/variant.hpp"
    #include <iostream>
    #include <vector>
    #include <list>
    #include <algorithm>

    class are_strict_equals
    : public boost::static_visitor<bool>
    {
    public:

    template <typename T, typename U>
    bool operator()( const T &, const U & ) const
    {
    return false; // cannot compare different types
    }

    template <typename T>
    bool operator()( const T & lhs, const T & rhs ) const
    {
    return lhs == rhs;
    }

    };

    int main(int argc, char* argv[])
    {
    boost::variant< int, std::string > v1( "hello" );

    boost::variant< double, std::string > v2( "hello" );
    assert( boost::apply_visitor(are_strict_equals(), v1, v2) );

    boost::variant< int, const char * > v3( "hello" );
    assert( !boost::apply_visitor(are_strict_equals(), v1, v3) );

    typedef boost::variant<double, std::string> my_variant;

    std::vector< my_variant > seq1;
    seq1.push_back("pi is close to ");
    seq1.push_back(3.14);

    std::list< my_variant > seq2;
    seq2.push_back("pi is close to ");
    seq2.push_back(3.14);

    are_strict_equals visitor;
    assert( std::equal(v1.begin(), v1.end(), v2.begin(),
    boost::apply_visitor( visitor ) ) );

    return 0;
    }
    morten, May 9, 2007
    #1
    1. Advertising

  2. morten schrieb:
    > When i compile this code in VC71 or VC80 i get the following errors:
    > The code is copy/paste from the boost.org tutorial. Please help!
    >
    > error C2039: 'begin' : is not a member of 'boost::variant<T0_,T1>'

    [...]

    begin and end are not members of boost::variant. Thats what the compiler
    says. In std::equal you want to compare seq1 and seq2 instead of v1 and v2.

    > int main(int argc, char* argv[])
    > {
    > boost::variant< int, std::string > v1( "hello" );
    >
    > boost::variant< double, std::string > v2( "hello" );
    > assert( boost::apply_visitor(are_strict_equals(), v1, v2) );
    >
    > boost::variant< int, const char * > v3( "hello" );
    > assert( !boost::apply_visitor(are_strict_equals(), v1, v3) );
    >
    > typedef boost::variant<double, std::string> my_variant;
    >
    > std::vector< my_variant > seq1;
    > seq1.push_back("pi is close to ");
    > seq1.push_back(3.14);
    >
    > std::list< my_variant > seq2;
    > seq2.push_back("pi is close to ");
    > seq2.push_back(3.14);
    >
    > are_strict_equals visitor;
    > assert( std::equal(v1.begin(), v1.end(), v2.begin(),
    > boost::apply_visitor( visitor ) ) );
    >
    > return 0;
    > }


    Looks like the boost.org tutorial is broken :)

    --
    Thomas
    http://www.netmeister.org/news/learn2quote.html
    Thomas J. Gritzan, May 10, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. RAB

    page visitation counter...

    RAB, Mar 22, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    375
    Alvin Bruney - ASP.NET MVP
    Mar 22, 2006
  2. =?ISO-8859-2?Q?Miros=B3aw?= Makowiecki

    The boost.variant library and boost::make_recursive_variant

    =?ISO-8859-2?Q?Miros=B3aw?= Makowiecki, Jul 5, 2007, in forum: C++
    Replies:
    1
    Views:
    684
    dasjotre
    Jul 6, 2007
  3. Replies:
    5
    Views:
    355
    Miroslaw Makowiecki
    Sep 29, 2007
  4. Tim Greer

    Re: Visitation Counter.

    Tim Greer, Jan 14, 2009, in forum: HTML
    Replies:
    0
    Views:
    348
    Tim Greer
    Jan 14, 2009
  5. DLU

    Visitation Counter.

    DLU, Jan 14, 2009, in forum: HTML
    Replies:
    7
    Views:
    435
Loading...

Share This Page