You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@qpid.apache.org by "Alan Conway (JIRA)" <ji...@apache.org> on 2016/06/01 17:33:59 UTC

[jira] [Comment Edited] (PROTON-1216) c++: proton::coerce() should allow conversion from binary.

    [ https://issues.apache.org/jira/browse/PROTON-1216?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15310716#comment-15310716 ] 

Alan Conway edited comment on PROTON-1216 at 6/1/16 5:33 PM:
-------------------------------------------------------------

Will fix, we should not suppress this. Needs a static_cast in corece to make it clear we mean it, the is_convertible test will protect us from over-casting. I did test on windows but just saw the green light, didnt check the warnings. Fix coming shortly. 

It would be good to make windows warning free and enable warnings-as-errors so this kind of thing can't be overlooked, but that might be a big job.



was (Author: aconway):
Will fix, we should not suppress this. Needs a static_cast in corece to make it clear we mean it, the is_convertible test will protect us from over-casting. I did test on windows but just saw the green light, didnt' check the warnings. Fix coming shortly.


> c++: proton::coerce<std::string>() should allow conversion from binary.
> -----------------------------------------------------------------------
>
>                 Key: PROTON-1216
>                 URL: https://issues.apache.org/jira/browse/PROTON-1216
>             Project: Qpid Proton
>          Issue Type: Bug
>          Components: cpp-binding
>    Affects Versions: 0.12.2
>            Reporter: Alan Conway
>            Assignee: Alan Conway
>             Fix For: 0.13.0
>
>
> proton::coerce<std::string> should convert a binary value to a std::string. The documentation also needs clarification: coerce should allow exactly those conversions that are allowed as implicit C++ conversions.
> Issue raised in excellent bug report on the user list http://qpid.2158936.n2.nabble.com/Proton-C-0-13-x-decode-binary-type-tp7644510p7644747.html text follows:
> proton::coerce (both forms) currently throws the same
> exception as proton::get, as does value.as_string(), although that doesn't
> appear to be in the public API. Not sure what 'd' was in the d>>b  example,
> but got a version working using value.get<std::binary>() and an implicit
> cast to std::string.
> To reproduce...
> #include <proton/value.hpp>
> #include <proton/binary.hpp>
> #include <proton/error.hpp>
> #include <iostream>
> template<typename Lambda>
> void expect_exception ( Lambda f )
> {
>   try
>   {
>     f();
>     std::cout << "*** FAIL (expected conversion error) ***" << std::endl;
>   }
>   catch ( const proton::conversion_error& e )
>   {
>     std::cout << "PASS" << std::endl;
>   }
> }
> template<typename Lambda>
> void expect_value ( const std::string& expected, Lambda f )
> {
>   try
>   {
>     std::cout << (f() == expected ? "PASS" : "*** FAIL (wrong value) ***")
> << std::endl;
>   }
>   catch ( const proton::conversion_error& e )
>   {
>     std::cout << "*** FAIL (conversion error) ***" << std::endl;
>   }
> }
> int main()
> {
>   std::string expected = "Hello World!";
>   proton::value value = proton::binary(expected);
>   expect_exception(      [=] { return value.get<std::string>();                
> });
>   expect_exception(      [=] { return proton::get<std::string>(value);         
> });
>   expect_exception(      [=] { std::string result;
> proton::get<std::string>(value); return result; });
>   expect_value(expected, [=] () -> std::string { return
> value.get<proton::binary>(); } );
>   // The following currently fail under 0.13.x
>   expect_value(expected, [=] { return value.as_string();                       
> });
>   expect_value(expected, [=] { return proton::coerce<std::string>(value);      
> });
>   expect_value(expected, [=] { std::string result;
> proton::coerce<std::string>(value, result); return result; });
>   
> }



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@qpid.apache.org
For additional commands, e-mail: dev-help@qpid.apache.org