Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > boost::variant Binary visitation

Reply
Thread Tools

boost::variant Binary visitation

 
 
morten
Guest
Posts: n/a
 
      05-09-2007
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;
}

 
Reply With Quote
 
 
 
 
Thomas J. Gritzan
Guest
Posts: n/a
 
      05-09-2007
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Visitation Counter. DLU HTML 7 01-18-2009 06:32 PM
Re: Visitation Counter. Tim Greer HTML 0 01-14-2009 04:49 PM
(8-bit binary to two digit bcd) or (8-bit binary to two digit seven segment) Fangs VHDL 3 10-26-2008 06:41 AM
page visitation counter... RAB ASP .Net 1 03-22-2006 07:49 PM
Re: ostreams, ios::binary, endian, mixed binary-ascii Marc Schellens C++ 8 07-15-2003 12:27 PM



Advertisments