Quantcast

[Fusion] wide-char output

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[Fusion] wide-char output

Boost - Users mailing list
Hi,
the documentation of the Boost.Fusion library (1.63.0) at
http://www.boost.org/doc/libs/1_63_0/libs/fusion/doc/html/fusion/sequence/operator/i_o/out.html
affirms that operator<< is defined in the boost::fusion namespace with
the following synopsis:

         template <typename OStream, typename Sequence>
         OStream&
         operator<<(OStream& os, Sequence& seq);

where the template parameter OStream is defined as "An output stream".
Accordingly, I thought that the following would work:

    using boost::fusion::operator<<;
    fusion::vector<int, double, const char *> v =
fusion::make_vector(42, 3.1415, "foobar");
    std::wcout << "v = " << v << std::endl;

However, the compiler (MSVC 9) complains that it has:

"found no defined operator << taking a right-hand argument of type
boost::fusion::vector<T0,T1,T2> with T0 = int, T1 = double, T2 = char
*"

If I replace std::wcout with its narrow-char sibling std::cout,
everything works as expected; i.e. the code compiles and when run
prints (42,3.1415, foobar).

Looking into the source (file boost/fusion/sequence/io/out.hpp) it
seems that the operator<< is only defined for left-hand argument of
type std::ostream.

Thus the questions:

  1. Is this a bug and should I post a ticket about it? (I looked in
the bugs database but I couldn't find it)
  2. If it's a bug, are there any plan to patch it soon?
  3. If not, does exist any reason why it shouldn't be patched nevertheless?

If needed, I could volunteer for writing a patch.

Thank for your attention

--
Leo Cacciari

Aliae nationes servitutem pati possunt. Populi Romani est propria libertas.
_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Fusion] wide-char output

Boost - Users mailing list
Leo Cacciari <[hidden email]> wrote:

> Accordingly, I thought that the following would work:
>
>     using boost::fusion::operator<<;
>     fusion::vector<int, double, const char *> v = fusion::make_vector(42, 3.1415, "foobar");
>     std::wcout << "v = " << v << std::endl;

Forgive me if I'm missing something obvious: Could the problem be that your passing char-based strings to an output stream expecting wchar_t-based text?

Couldn't you fix this by writing to std:cout instead of std::wcout?

|+|  M a r k  |+|

Mark Stallard
Business Application Services
Global Business Services Information Technology
Raytheon Company
 

_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Fusion] wide-char output

Boost - Users mailing list
AMDG

On 04/05/2017 10:43 AM, Mark Stallard via Boost-users wrote:

> Leo Cacciari <[hidden email]> wrote:
>
>> Accordingly, I thought that the following would work:
>>
>>     using boost::fusion::operator<<;
>>     fusion::vector<int, double, const char *> v = fusion::make_vector(42, 3.1415, "foobar");
>>     std::wcout << "v = " << v << std::endl;
>
> Forgive me if I'm missing something obvious: Could the problem be that your passing char-based strings to an output stream expecting wchar_t-based text?
>
> Couldn't you fix this by writing to std:cout instead of std::wcout?
>

basic_ostream has an overload for const char * in
addition to const CharT*.

In Christ,
Steven Watanabe

_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Fusion] wide-char output

Boost - Users mailing list
In reply to this post by Boost - Users mailing list
AMDG

On 04/05/2017 09:10 AM, Leo Cacciari via Boost-users wrote:

> the documentation of the Boost.Fusion library (1.63.0) at
> http://www.boost.org/doc/libs/1_63_0/libs/fusion/doc/html/fusion/sequence/operator/i_o/out.html
> affirms that operator<< is defined in the boost::fusion namespace with
> the following synopsis:
>
>          template <typename OStream, typename Sequence>
>          OStream&
>          operator<<(OStream& os, Sequence& seq);
>
> where the template parameter OStream is defined as "An output stream".
>
> <snip>
>
> Looking into the source (file boost/fusion/sequence/io/out.hpp) it
> seems that the operator<< is only defined for left-hand argument of
> type std::ostream.
>
> Thus the questions:
>
>   1. Is this a bug and should I post a ticket about it? (I looked in
> the bugs database but I couldn't find it)

  It's definitely a bug.  Whether the bug is in
the documentation or in the source, I can't say.
Personally, I think both are wrong, and the
correct signature is
template<class CharT, class Traits, class Sequence>
std::basic_ostream<CharT, Traits>& operator<<(
  std::basic_ostream<CharT, Traits>&, Sequence const&);

>   2. If it's a bug, are there any plan to patch it soon?
>   3. If not, does exist any reason why it shouldn't be patched nevertheless?
>

In Christ,
Steven Watanabe

_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Fusion] wide-char output

Boost - Users mailing list
In reply to this post by Boost - Users mailing list
On Wed, Apr 5, 2017 at 6:43 PM, Mark Stallard <[hidden email]> wrote:
> Forgive me if I'm missing something obvious: Could the problem be that your passing char-based strings to an output stream expecting wchar_t-based text?
>

No, it's a 'char *', not a std::string, and this is definitely valid:

    std::cout << "foobar" << std::endl;


> Couldn't you fix this by writing to std:cout instead of std::wcout?

No, because the actual structure I will use contains members that are
std::wstring (and those can not be sent to std::cout directly).

Nor can those std::wstring be made std::string. Leaving out the hassle
of converting the encoding without a C+11 compiler (I'm stuck with
MSVC9), there is the problem that these data are windows system data
(device properties, in fact) that must be read and writen back in wide
char. So I'll have to convert between 8- and 16-bits encoding all the
time... Ugly! :)





--
Leo Cacciari

Aliae nationes servitutem pati possunt. Populi Romani est propria libertas.
_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Loading...