473,396 Members | 1,725 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

boost::variant Binary visitation

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::stringmy_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;
}

May 9 '07 #1
1 4557
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::stringmy_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
May 9 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Steve Knight | last post by:
Hello, I'm new to Boost & Python and I'm diving straight in by trying to write an extension module to a third party library. Foolishness probably, but I don't have much choice! My question...
5
by: rob | last post by:
hey every1, I've got alot of data to write out to file and it's all just 1's and 0's. It's all stored in 2 dimensional arrays of width 32 and varying height. At the moment it's all just...
7
by: sbobrows | last post by:
{Whilst I think much of this is OT for this newsgroup, I think the issue of understanding diagnostics just about gets under the door. -mod} Hi, I'm a C++ newbie trying to use the Boost regex...
103
by: Steven T. Hatton | last post by:
§27.4.2.1.4 Type ios_base::openmode Says this about the std::ios::binary openmode flag: *binary*: perform input and output in binary mode (as opposed to text mode) And that is basically _all_ it...
0
by: Andrew Ayre | last post by:
Hi, I can't seem to get the library built, and any help is greatly appreciated. Here is the info: Windows XP Borland C++ Builder 5 Latest Boost source code (downloaded at the weekend) Windows...
1
by: Flash Gordon | last post by:
ok here is the problem: I need to have a map of variants that actually vary *only* at initialization, i.e. vmap = variant<int, float>(1); // constructed as int vmap = variant<int,...
5
by: miroslaw.makowiecki | last post by:
How do we think about optymalization boost.variant on account of a memory and a speed of action in its boost library in C++ language. Advice in thanks.
2
by: mkvenkit.vc | last post by:
Hello, I hope this is the right place to post a question on Boost. If not, please let me know where I can post this message and I will do so. I am having a strange problem with std::string as...
1
by: captainc | last post by:
I have C++ code to import a .tlb and use a .dll that has functions that return VARIANT types and accepts BSTRs (bstrings). I have seen that python has modules that can manipulate VARIANTs and BSTRs...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.