Serializing UUIDs into text archives

Serializing a UUID into a boost::archive::binary_[io]archive works fine. However, when changing to a text archive, I get a compiler error with gcc 4.7 in C++11 mode on Darwin. Here is a small example: #include <boost/archive/text_oarchive.hpp> #include <boost/iostreams/device/back_inserter.hpp> #include <boost/iostreams/filtering_stream.hpp> #include <boost/uuid/uuid_generators.hpp> #include <boost/uuid/uuid_serialize.hpp> int main() { std::vector<char> v; boost::iostreams::filtering_ostream stream(boost::iostreams::back_inserter(v)); boost::archive::text_oarchive oa(stream); boost::uuids::uuid id = boost::uuids::random_generator()(); oa << id; return 0; } The error is in basic_text_oprimitive line 92: cannot bind 'std::basic_ostream<char>' lvalue to 'std::basic_ostream<char>&&' Any ideas what's going on? (I attached the full error message below.) Matthias In file included from /opt/local/include/boost/archive/text_oarchive.hpp:30:0, from test.cc:2: /opt/local/include/boost/archive/basic_text_oprimitive.hpp: In instantiation of 'void boost::archive::basic_text_oprimitive<OStream>::save(const T&) [with T = boost::uuids::uuid; OStream = std::basic_ostream<char>]': /opt/local/include/boost/archive/text_oarchive.hpp:61:9: required from 'void boost::archive::text_oarchive_impl<Archive>::save(const T&) [with T = boost::uuids::uuid; Archive = boost::archive::text_oarchive]' /opt/local/include/boost/archive/detail/oserializer.hpp:88:9: required from 'static void boost::archive::save_access::save_primitive(Archive&, const T&) [with Archive = boost::archive::text_oarchive; T = boost::uuids::uuid]' /opt/local/include/boost/archive/detail/oserializer.hpp:232:13: required from 'static void boost::archive::detail::save_non_pointer_type<Archive>::save_primitive::invoke(Archive&, const T&) [with T = boost::uuids::uuid; Archive = boost::archive::text_oarchive]' /opt/local/include/boost/archive/detail/oserializer.hpp:308:9: required from 'static void boost::archive::detail::save_non_pointer_type<Archive>::invoke(Archive&, const T&) [with T = boost::uuids::uuid; Archive = boost::archive::text_oarchive]' /opt/local/include/boost/archive/detail/oserializer.hpp:314:9: required from 'static void boost::archive::detail::save_non_pointer_type<Archive>::invoke(Archive&, T&) [with T = boost::uuids::uuid; Archive = boost::archive::text_oarchive]' /opt/local/include/boost/archive/detail/oserializer.hpp:525:5: required from 'void boost::archive::save(Archive&, T&) [with Archive = boost::archive::text_oarchive; T = boost::uuids::uuid]' /opt/local/include/boost/archive/detail/common_oarchive.hpp:69:9: required from 'void boost::archive::detail::common_oarchive<Archive>::save_override(T&, int) [with T = boost::uuids::uuid; Archive = boost::archive::text_oarchive]' /opt/local/include/boost/archive/basic_text_oarchive.hpp:80:9: required from 'void boost::archive::basic_text_oarchive<Archive>::save_override(T&, int) [with T = boost::uuids::uuid; Archive = boost::archive::text_oarchive]' /opt/local/include/boost/archive/detail/interface_oarchive.hpp:63:9: required from 'Archive& boost::archive::detail::interface_oarchive<Archive>::operator<<(T&) [with T = boost::uuids::uuid; Archive = boost::archive::text_oarchive]' test.cc:15:11: required from here /opt/local/include/boost/archive/basic_text_oprimitive.hpp:92:9: error: cannot bind 'std::basic_ostream<char>' lvalue to 'std::basic_ostream<char>&&' In file included from /opt/local/include/boost/archive/text_oarchive.hpp:19:0, from test.cc:2: /opt/local/include/gcc47/c++/ostream:600:5: error: initializing argument 1 of 'std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&&, const _Tp&) [with _CharT = char; _Traits = std::char_traits<char>; _Tp = boost::uuids::uuid]'

Matthias Vallentin wrote:
Serializing a UUID into a boost::archive::binary_[io]archive works fine. However, when changing to a text archive, I get a compiler error with gcc 4.7 in C++11 mode on Darwin. Here is a small example:
#include <boost/archive/text_oarchive.hpp> #include <boost/iostreams/device/back_inserter.hpp> #include <boost/iostreams/filtering_stream.hpp> #include <boost/uuid/uuid_generators.hpp> #include <boost/uuid/uuid_serialize.hpp>
int main() { std::vector<char> v; boost::iostreams::filtering_ostream stream(boost::iostreams::back_inserter(v)); boost::archive::text_oarchive oa(stream);
const boost::uuids::uuid id = boost::uuids::random_generator()(); // try adding const here !! oa << id;
return 0; }
The error is in basic_text_oprimitive line 92:
cannot bind 'std::basic_ostream<char>' lvalue to 'std::basic_ostream<char>&&'
Any ideas what's going on? (I attached the full error message below.)
Matthias
Robert Ramey

Matthias Vallentin wrote:
Serializing a UUID into a boost::archive::binary_[io]archive works fine. However, when changing to a text archive, I get a compiler error with gcc 4.7 in C++11 mode on Darwin. Here is a small example:
#include <boost/archive/text_oarchive.hpp> #include <boost/iostreams/device/back_inserter.hpp> #include <boost/iostreams/filtering_stream.hpp> #include <boost/uuid/uuid_generators.hpp> #include <boost/uuid/uuid_serialize.hpp>
int main() { std::vector<char> v; boost::iostreams::filtering_ostream stream(boost::iostreams::back_inserter(v)); boost::archive::text_oarchive oa(stream);
boost::uuids::uuid id = boost::uuids::random_generator()(); oa << id;
return 0; }
The error is in basic_text_oprimitive line 92:
cannot bind 'std::basic_ostream<char>' lvalue to 'std::basic_ostream<char>&&'
Any ideas what's going on? (I attached the full error message below.)
Matthias
In file included from
/opt/local/include/boost/archive/text_oarchive.hpp:30:0, from test.cc:2: /opt/local/include/boost/archive/basic_text_oprimitive.hpp: In instantiation of 'void boost::archive::basic_text_oprimitive<OStream>::save(const T&) [with T = boost::uuids::uuid; OStream = std::basic_ostream<char>]':
This looks to me to some issue with boost::io_streams. Try your example with a regular stream (e.g. std::fostream). Robert Ramey

This looks to me to some issue with boost::io_streams. Try your example with a regular stream (e.g. std::fostream).
Same error with a regular stream, here's the current example: #include <fstream> #include <boost/archive/text_oarchive.hpp> #include <boost/uuid/uuid_generators.hpp> #include <boost/uuid/uuid_serialize.hpp> int main() { std::vector<char> v; std::ofstream f("/tmp/foo"); boost::archive::text_oarchive oa(f); boost::uuids::uuid id = boost::uuids::random_generator()(); oa << id; return 0; } Matthias

Matthias Vallentin wrote:
This looks to me to some issue with boost::io_streams. Try your example with a regular stream (e.g. std::fostream).
Same error with a regular stream, here's the current example:
#include <fstream> #include <boost/archive/text_oarchive.hpp> #include <boost/uuid/uuid_generators.hpp> #include <boost/uuid/uuid_serialize.hpp>
int main() { std::vector<char> v; std::ofstream f("/tmp/foo"); boost::archive::text_oarchive oa(f);
const boost::uuids::uuid id = boost::uuids::random_generator()(); // try const oa << id;
return 0; }
Matthias _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

int main() { std::vector<char> v; std::ofstream f("/tmp/foo"); boost::archive::text_oarchive oa(f);
const boost::uuids::uuid id = boost::uuids::random_generator()(); // try const
Sorry, I should have added that I actually tried both const and non-const versions, per your earlier suggestion. Making the uuid const does not seem to have an effect. Matthias
participants (2)
-
Matthias Vallentin
-
Robert Ramey