Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std::wstring #309

Open
TylerTheFox opened this issue Jun 29, 2016 · 4 comments
Open

std::wstring #309

TylerTheFox opened this issue Jun 29, 2016 · 4 comments

Comments

@TylerTheFox
Copy link

Can you use serialize wide strings? (http://www.cplusplus.com/reference/string/wstring/)

1>cereal\inc\cereal/archives/json.hpp(879): error C2664: 'void cereal::JSONOutputArchive::saveValue(unsigned long)': cannot convert argument 1 from 'const std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t>>' to 'bool' (compiling source file .cpp)
1> cereal\inc\cereal/archives/json.hpp(879): note: No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called (compiling source file .cpp)
1> cereal\inc\cereal/cereal.hpp(410): note: see reference to function template instantiation 'void cereal::save<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t>>(cereal::JSONOutputArchive &,const std::basic_string<wchar_t,std::char_traits<wchar_t>,std::allocator<wchar_t>> &)' being compiled (compiling source file .cpp)
1> cereal\inc\cereal/cereal.hpp(333): note: see reference to function template instantiation 'ArchiveType &cereal::OutputArchive<ArchiveType,0>::processImplstd::wstring,0(const T &)' being compiled

@AzothAmmo
Copy link
Contributor

This is not yet supported, see #95

@tristanl-slalom
Copy link

Is there a workaround? I'm trying to integrate cereal with legacy code, and they use wstring for everything.

@TylerTheFox
Copy link
Author

std::wstring only works in the binary output/input archive. That was how I worked around it.

@zhuebok
Copy link

zhuebok commented Apr 6, 2018

Next code allows to solve this problem (but it would work for std::wstring only, not for std::basic_string<wchar_t, custom...>):

namespace cereal
{
	template<class A>
	std::string CEREAL_SAVE_MINIMAL_FUNCTION_NAME( A const &, const std::wstring &in )
	{
		return boost::locale::conv::utf_to_utf<char>( in );
	}

	template<class A>
	void CEREAL_LOAD_MINIMAL_FUNCTION_NAME( A const &, std::wstring &out, const std::string &in )
	{
		out = boost::locale::conv::utf_to_utf<wchar_t>( in );
	}
}

CEREAL_SPECIALIZE_FOR_ALL_ARCHIVES( std::wstring, cereal::specialization::non_member_load_save_minimal );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants