|
Boost Users : |
From: Ovanes Markarian (om_boost_at_[hidden])
Date: 2006-06-26 03:14:02
Hi!
Can you please to compile this code either with string in the variant or a
vector.
Not sure if it helps but the variant documentation at
http://www.boost.org/doc/html/variant/reference.html states:
namespace boost {
template<typename T1, typename T2 = unspecified, ...,
typename TN = unspecified>
class variant;
template<typename Sequence> class make_variant_over;
template<typename T1, typename T2, ..., typename TN>
void swap(variant<T1, T2, ..., TN> &, variant<T1, T2, ..., TN> &);
template<typename ElemType, typename Traits, typename T1, typename T2,
...,
typename TN>
std::basic_ostream<ElemType,Traits> &
operator<<(std::basic_ostream<ElemType,Traits> &,
const variant<T1, T2, ..., TN> &); }
Which means that the types are not zero-index based. So your T5 would be a
string and not a vector. Make some tests like with simple integers, strings
and finally a vector and see what happens.
Best Regards,
Ovanes
-----Original Message-----
From: Nindi [mailto:Nindi73_at_[hidden]]
Sent: Sunday, June 25, 2006 15:36
To: boost-users_at_[hidden]
Subject: [Boost-users] Boost Variant OutputStreamable
I have started using Boost recently, and though I should switch my own
variant to the Boost Variant . However I cannot compile the following code
#include<iostream>
#include<vector>
#include<string>
#include<boost/variant.hpp>
std::basic_ostream<char> &operator<<(std::basic_ostream<char>
&theostream,const std::vector<unsigned long> &theVector)
{
for(unsigned long i(0);i<theVector.size();i++)
theostream << theVector[i] << "\n" ;
return theostream;
}
struct TpTemplateVariant {
typedef boost::variant< int,
unsigned long,
double,
bool,
std::string,
std::vector<unsigned long>
> BoostVariant;
};
typedef TpTemplateVariant::BoostVariant Tpvariant;
int main () {
Tpvariant p(5);
std::cout << p;
return 0;
}
The error I get is
error C2679: binary '<<' : no operator found which takes a right-hand
operand of type 'const T5'
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