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

ASF subversion and git services commented on PROTON-1216:
---------------------------------------------------------

Commit 7cc9562cd6c83f995586e56f939072213ce60cae in qpid-proton's branch 
refs/heads/0.13.x from [~aconway]
[ https://git-wip-us.apache.org/repos/asf?p=qpid-proton.git;h=7cc9562 ]

PROTON-1216: c++: proton::coerce should convert binary to string.

Make scalar and value coerce<> consistent with C++ implicit conversions and 
each other.

- No source api change (still have deprecated functions)
- Better test coverage, consistent tests for value and scalar where applicable.
- Fixed unknown integer type conversions for scalar.
- Fixed examples using deprecated APIs (deprecated APIs are still in place)
- Consistent printing of scalar values, repect the std::ios::boolalpha flag for 
printing bool.

This commit also includes the following 2 commits from master:

PROTON-1216: c++: cleanup to previous commit.

Removed file left behind in error, removed non standard cxxabi.h.

PROTON-1216: Fix windows warnings from is_convertible<>

Locally suppress Windows warnings about legal but risky argument
conversions (float/int, signed/unsigned etc.) only in template is_convertible<>.

The compile-time warnings are a side effect of template instantiation by
coerce<>, not an indication of risky use. coerce<> is a run-time conversion and
throws run-time errors for illegal conversions. In future we may add something
like safe_convert<> that throws run-time errors for risky conversions as well.


> 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-unsubscr...@qpid.apache.org
For additional commands, e-mail: dev-h...@qpid.apache.org

Reply via email to