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

   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); ///
        if (this->apply_visitor(direct_assign) == false)<---------

the variant template arguments

digging deeper I found that the reason is in direct_assigner visitor

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

private: // representation

    T& rhs_; // <---------------------------------------



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


Boost list run by bdawes at, gregod at, cpdaniel at, john at