std::basic_string<unsigned char>s;boost::lexical_cast<unsigned int>(s);
От: syvyi Россия  
Дата: 15.06.13 22:57
Оценка:
Добрый вечер!
Код типа, приведённого в "топике" "не хавается" по следующей причине

d:\cpp\boost\boost_1_53_0\boost_1_53_0\boost\lexical_cast.hpp(1513): error C2784: 'std::basic_ostream<_Elem,_Traits> &std::operator <<(std::basic_ostream<_Elem,_Traits> &,const std::shared_ptr<_Ty> &)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'boost::detail::do_not_construct_out_stream_t'
1> d:\visual studio 11.0\vc\include\memory(813) : see declaration of 'std::operator <<'
1> d:\cpp\boost\boost_1_53_0\boost_1_53_0\boost\lexical_cast.hpp(1793) : see reference to function template instantiation 'bool boost::detail::lexical_stream_limited_src<CharT,Traits,RequiresStringbuffer>::shl_input_streamable<const InStreamable>(InputStreamable &)' being compiled
1> with
1> [
1> CharT=char,
1> Traits=std::char_traits<char>,
1> RequiresStringbuffer=false,
1> InStreamable=src,
1> InputStreamable=src
1> ]
1> d:\cpp\boost\boost_1_53_0\boost_1_53_0\boost\lexical_cast.hpp(1793) : see reference to function template instantiation 'bool boost::detail::lexical_stream_limited_src<CharT,Traits,RequiresStringbuffer>::shl_input_streamable<const InStreamable>(InputStreamable &)' being compiled
1> with
1> [
1> CharT=char,
1> Traits=std::char_traits<char>,
1> RequiresStringbuffer=false,
1> InStreamable=src,
1> InputStreamable=src
1> ]
1> d:\cpp\boost\boost_1_53_0\boost_1_53_0\boost\lexical_cast.hpp(2236) : see reference to function template instantiation 'bool boost::detail::lexical_stream_limited_src<CharT,Traits,RequiresStringbuffer>::operator <<<Source>(const InStreamable &)' being compiled
1> with
1> [
1> CharT=char,
1> Traits=std::char_traits<char>,
1> RequiresStringbuffer=false,
1> Source=src,
1> InStreamable=src
1> ]
1> d:\cpp\boost\boost_1_53_0\boost_1_53_0\boost\lexical_cast.hpp(2236) : see reference to function template instantiation 'bool boost::detail::lexical_stream_limited_src<CharT,Traits,RequiresStringbuffer>::operator <<<Source>(const InStreamable &)' being compiled
1> with
1> [
1> CharT=char,
1> Traits=std::char_traits<char>,
1> RequiresStringbuffer=false,
1> Source=src,
1> InStreamable=src
1> ]
1> d:\cpp\boost\boost_1_53_0\boost_1_53_0\boost\lexical_cast.hpp(2218) : while compiling class template member function 'unsigned int boost::detail::lexical_cast_do_cast<Target,Source>::lexical_cast_impl(const Source &)'
1> with
1> [
1> Target=unsigned int,
1> Source=src
1> ]
1> d:\cpp\boost\boost_1_53_0\boost_1_53_0\boost\lexical_cast.hpp(2405) : see reference to function template instantiation 'unsigned int boost::detail::lexical_cast_do_cast<Target,Source>::lexical_cast_impl(const Source &)' being compiled
1> with
1> [
1> Target=unsigned int,
1> Source=src
1> ]
1> d:\cpp\boost\boost_1_53_0\boost_1_53_0\boost\lexical_cast.hpp(2405) : see reference to class template instantiation 'boost::detail::lexical_cast_do_cast<Target,Source>' being compiled
1> with
1> [
1> Target=unsigned int,
1> Source=src
1> ]
1> (СКРЫТО автором сия сообщения) : see reference to function template instantiation 'Target boost::lexical_cast<unsigned int,com_port::bytes_container>(const Source &)' being compiled
1> with
1> [
1> Target=unsigned int,
1> Source=com_port::bytes_container
1> ]

Вразумите.
cpp boost lexical_cast unsigned char
Re: std::basic_string<unsigned char>s;boost::lexical_cast<unsigned int>(s);
От: Кодт Россия  
Дата: 16.06.13 11:27
Оценка:
Здравствуйте, syvyi, Вы писали:

S>Добрый вечер!

S>Код типа, приведённого в "топике" "не хавается" по следующей причине

По причине того, что lexical_cast в своих недрах (в частности, lcast_char_constants<CharT>) специализирован лишь для следующих типов символов:
— char
— wchar_t
— char16_t, char32_t — платформенно-зависимо
Но не для unsigned char.

Лечится элементарно, отказом от std::basic_string<unsigned char> в пользу обычной std::string.
Перекуём баги на фичи!
Re[2]: std::basic_string<unsigned char>s;boost::lexical_cast<unsigned int>(s);
От: syvyi Россия  
Дата: 16.06.13 17:06
Оценка:
Здравствуйте, Кодт, Вы писали:

К>Здравствуйте, syvyi, Вы писали:


S>>Добрый вечер!

S>>Код типа, приведённого в "топике" "не хавается" по следующей причине

К>По причине того, что lexical_cast в своих недрах (в частности, lcast_char_constants<CharT>) специализирован лишь для следующих типов символов:

К>- char
К>- wchar_t
К>- char16_t, char32_t — платформенно-зависимо
К>Но не для unsigned char.

К>Лечится элементарно, отказом от std::basic_string<unsigned char> в пользу обычной std::string.

Вопрос поэтому и был задан, что такое решение не подходит.
Re[3]: std::basic_string<unsigned char>s;boost::lexical_cast<unsigned int>(s);
От: Кодт Россия  
Дата: 16.06.13 20:19
Оценка: 1 (1)
Здравствуйте, syvyi, Вы писали:

К>>Лечится элементарно, отказом от std::basic_string<unsigned char> в пользу обычной std::string.

S>Вопрос поэтому и был задан, что такое решение не подходит.

Ну хозяин-барин, хочется извращаться с нетипичными контейнерами, пожалуйста. std::iostream тоже ведь поломается.

Если нравится расставлять костыли в программе, то выход прост:
boost::lexical_cast<unsigned int>( (char const*) s.c_str() )

ну или, чтобы в ста местах не повторяться,
template<class T, class F>
T my_lexical_cast(F const& f)
{ return boost::lexical_cast<T>(f); }

template<class T>
T my_lexical_cast(std::string<unsigned char> const& s)
{ return my_lexical_cast<T>((char const*)s.c_str()); }
Перекуём баги на фичи!
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.