Boost logo

Boost :

Subject: [boost] boost::iterator_range does not work in boost::variant in boost 1.55
From: Jon Biggar (jon_at_[hidden])
Date: 2014-03-01 22:24:07


If I try to put a boost::iterator_range into a boost::variant, it breaks
the variant, because something in boost::iterator_range doesn't allow
variant to use SFINAE deduction. My best guess at the problem is the
declarations in boost/range/iterator_range_core.hpp that have a 'class
ForwardRange' template argument are insufficiently constrained
and accept almost anything as a possible ForwardRange type.

I'm guessing that putting the correct enable_if<> template constraints
on the templates that use 'ForwardRange' will fix the issue, but I'm
having trouble identifing the correct metafunction test to use, since
concept FowardRange concept doesn't have too many good targets.

I'd like to test a candidate FowardRange type to see if boost::begin()
and boost::end() can be successfully called on it, but I haven't figured
out how to do that yet.

Any suggestions? Known fixes or workarounds? I know about the
has_range_iterator metafunction, but it can't be used here due to
circular definition issues...

Exmaple:

#include <boost/variant.hpp>
#include <boost/range.hpp>
#include <boost/mpl/vector.hpp>

using namespace boost;

enum E {
     e1, e2, e3
};

typedef mpl::vector<E, std::string > args;
typedef boost::make_variant_over<args>::type OkVariant;

typedef mpl::vector<boost::iterator_range<std::string::iterator>, args>
args1;
typedef boost::make_variant_over<args1>::type BrokenVariant;

int main(int argc, char **argv)
{
     OkVariant ok;
     ok = e1;
     ok = "";

     BrokenVariant broken;
     std::string s;
     broken = boost::iterator_range<std::string::iterator>(s.begin(),
s.end());

     broken = e2;
     broken = "";
}

Yields errors on the last two assignments to 'broken' in g++4.8.2:

test.cpp:27:12: required from here
./boost/mpl/eval_if.hpp:60:31: error: no type named 'type' in
'boost::mpl::eval_if_c<true, boost::range_const_iterator<E>,
boost::range_mutable_iterator<const E> >::f_ {aka struct
boost::range_const_iterator<E>}'
      typedef typename f_::type type;

I've attached the full error log and my project-config.jam.

-- 
Jon Biggar
jon_at_[hidden]
jon_at_[hidden]
jonbiggar_at_[hidden]





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