no matching function for call to boost::algorithm::split

Hi, I'm trying to compile the following code with g++, but it generates an error. It compiles fine in VC8. typedef vector<string> to_t; to_t to; split(to, row.f(2).s(), is_any_of(",")); error: no matching function for call to 'split(main()::to_t&, std::string, boost::algorithm::detail::is_any_ofF<char>)' /usr/include/boost/algorithm/string/split.hpp:143: note: candidates are: SequenceSequenceT& boost::algorithm::split(SequenceSequenceT&, RangeT&, PredicateT, boost::algorithm::token_compress_mode_type) [with SequenceSequenceT = main()::to_t, RangeT = std::string, PredicateT = boost::algorithm::detail::is_any_ofF<char>] Does anyone know what I'm doing wrong? $ g++ -v Using built-in specs. Target: i486-linux-gnu Configured with: ../src/configure -v --enable-languages=c,c++,java,fortran,objc,obj-c++,ada,treelang --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --program-suffix=-4.1 --enable-__cxa_atexit --enable-clocale=gnu --enable-libstdcxx-debug --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-4.1-1.4.2.0/jre --enable-mpfr --with-tune=i686 --enable-checking=release i486-linux-gnu Thread model: posix gcc version 4.1.0 20060127 (prerelease)

Hi, I'm not sure. The code snippet you sent seems fine, so maybe the problem is elsewhere. I would check includes and namespaces. Regards, Pavol. On Tue, Mar 14, 2006 at 09:17:18PM +0100, Olaf van der Spek wrote:
Hi,
I'm trying to compile the following code with g++, but it generates an error. It compiles fine in VC8.
typedef vector<string> to_t; to_t to; split(to, row.f(2).s(), is_any_of(","));
error: no matching function for call to 'split(main()::to_t&, std::string, boost::algorithm::detail::is_any_ofF<char>)' /usr/include/boost/algorithm/string/split.hpp:143: note: candidates are: SequenceSequenceT& boost::algorithm::split(SequenceSequenceT&, RangeT&, PredicateT, boost::algorithm::token_compress_mode_type) [with SequenceSequenceT = main()::to_t, RangeT = std::string, PredicateT = boost::algorithm::detail::is_any_ofF<char>]
Does anyone know what I'm doing wrong?
$ g++ -v Using built-in specs. Target: i486-linux-gnu Configured with: ../src/configure -v --enable-languages=c,c++,java,fortran,objc,obj-c++,ada,treelang --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --program-suffix=-4.1 --enable-__cxa_atexit --enable-clocale=gnu --enable-libstdcxx-debug --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-4.1-1.4.2.0/jre --enable-mpfr --with-tune=i686 --enable-checking=release i486-linux-gnu Thread model: posix gcc version 4.1.0 20060127 (prerelease) _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

On 3/14/06, Pavol Droba <droba@topmail.sk> 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>]'

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@topmail.sk> 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
participants (2)
-
Olaf van der Spek
-
Pavol Droba