Boost logo

Boost :

From: Pavol Droba (droba_at_[hidden])
Date: 2006-03-14 16:40:27


Ok, I see the problem now. You cannot pass a temporary value into the split
algorithm.

The reason for this comes from a possibility to store result in a container
of iterator_range's. In other word, the result will be just a reference to the
input.

So to workaround your problem, simply create a local variable, that will hold
the input.

Regards,
Pavol

On Tue, Mar 14, 2006 at 10:13:43PM +0100, Olaf van der Spek wrote:
> On 3/14/06, Pavol Droba <droba_at_[hidden]> wrote:
> > Hi,
> >
> > I'm not sure. The code snippet you sent seems fine, so maybe the problem
> > is elsewhere. I would check includes and namespaces.
>
> I've now got:
> #include <boost/algorithm/string.hpp>
> #include <string>
> #include <vector>
>
> std::string f()
> {
> return "";
> }
>
> int main()
> {
> std::vector<std::string> v;
> boost::split(v, f(), boost::is_any_of(","));
> return 0;
> }
>
> split_test.cpp: In function 'int main()':
> split_test.cpp:13: error: invalid initialization of non-const
> reference of type 'std::string&' from a temporary of type
> 'std::string'
> /usr/include/boost/algorithm/string/split.hpp:143: error: in passing
> argument 2 of 'SequenceSequenceT&
> boost::algorithm::split(SequenceSequenceT&, RangeT&, PredicateT,
> boost::algorithm::token_compress_mode_type) [with SequenceSequenceT =
> std::vector<std::basic_string<char, std::char_traits<char>,
> std::allocator<char> >, std::allocator<std::basic_string<char,
> std::char_traits<char>, std::allocator<char> > > >, RangeT =
> std::string, PredicateT = boost::algorithm::detail::is_any_ofF<char>]'
> _______________________________________________
> Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost


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