Boost logo

Boost :

From: arun.s (arun.sivaramakrishnan_at_[hidden])
Date: 2006-06-02 04:07:37


Im trying to initialize boost variant ( from boost_1_33_1) as below in
MSVC8

   variant<char* , int> v ;
   v = 2;

I find that the the direct_assigner always fails and returns false in assign
method of variant.

template <class ....
class variant
{
...........
    template <typename T>
    void assign(const T& rhs)
    {
        // If direct T-to-T assignment is not possible...
        detail::variant::direct_assigner<const T> direct_assign(rhs); ///
---------------(1)
        if (this->apply_visitor(direct_assign) == false)<---------

the variant template arguments

digging deeper I found that the reason is in direct_assigner visitor
interface

template <typename T>
class direct_assigner
    : public static_visitor<bool>
{

private: // representation

    T& rhs_; // <---------------------------------------
(2)

....
...

#if !BOOST_WORKAROUND(BOOST_MSVC, <= 1200)

public: // visitor interface

    bool operator()(T& lhs) //<--------------------(3) is never called
    {
        lhs = rhs_;
        return true;
    }

    template <typename U>
    bool operator()(U&)
    {
        return false; ////<---------we always hit this
    }

The operator() in statement (3) is never called since T is of const type (
as set in statement (1) above in assign method of variant).
bit variant template argument is not const.

Shouldnt 'const' be prepended to statement (2) instead of prepending it in
(1)?

Thanks,
Arun


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk