forked from boostorg/endian
Remove "explicit" from Endian type constructors. Rationale: Having to write "cntr.insert(big_int32_t(value))" instead of "cntr.insert(value)" gets old fast when you are writing application code and the use case arises more or less continuously. Additionally, the use of an endian type is an implementation detail that should not leak into the application code that needs to create values of the type. Furthermore, the ambiguities that caused the constructors to be made explicit no longer occur; they were eliminated when BOOST_MINIMAL_INTEGER_COVER_OPERATORS was introduced to removed a dependency on boost/operators.hpp. If an ambiguity does arise, it is easy to clear via a static_cast or a function-style cast.
This commit is contained in:
@@ -42,6 +42,8 @@
|
||||
# pragma warning( disable : 4389 ) // signed/unsigned mismatch
|
||||
#endif
|
||||
|
||||
#define BOOST_ENDIAN_LOG
|
||||
|
||||
#include <boost/endian/types.hpp>
|
||||
#include <boost/type_traits/is_signed.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
@@ -341,6 +343,8 @@ void op_test()
|
||||
#endif
|
||||
}
|
||||
|
||||
void f_big_int32_t(be::big_int32_t) {}
|
||||
|
||||
// main ------------------------------------------------------------------------------//
|
||||
|
||||
int cpp_main(int, char * [])
|
||||
@@ -364,6 +368,13 @@ int cpp_main(int, char * [])
|
||||
be::little_uint16_t little_u(10);
|
||||
be::big_int64_t result;
|
||||
|
||||
// this is the use case that is so irritating that it caused the endian
|
||||
// constructors to be made non-explicit
|
||||
std::clog << "\nf(1234) where f(big_int32_t)\n";
|
||||
f_big_int32_t(1234);
|
||||
|
||||
std::clog << "\nresult = big\n";
|
||||
result = big;
|
||||
|
||||
std::clog << "\nresult = +big\n";
|
||||
result = +big;
|
||||
@@ -417,21 +428,26 @@ int cpp_main(int, char * [])
|
||||
result = 5 * 10;
|
||||
std::clog << "\n";
|
||||
|
||||
be::endian_log = false;
|
||||
|
||||
// test from Roland Schwarz that detected ambiguities
|
||||
// test from Roland Schwarz that detected ambiguities; these ambiguities
|
||||
// were eliminated by BOOST_MINIMAL_INTEGER_COVER_OPERATORS
|
||||
unsigned u;
|
||||
be::little_uint32_t u1;
|
||||
be::little_uint32_t u2;
|
||||
|
||||
u = 1;
|
||||
u = 9;
|
||||
u1 = 1;
|
||||
std::clog << "\nu2 = u1 + u\n";
|
||||
u2 = u1 + u;
|
||||
std::clog << "\n";
|
||||
|
||||
// one more wrinkle
|
||||
be::little_uint16_t u3(3);
|
||||
u3 = 3;
|
||||
std::clog << "\nu2 = u1 + u3\n";
|
||||
u2 = u1 + u3;
|
||||
std::clog << "\n";
|
||||
|
||||
be::endian_log = false;
|
||||
|
||||
// perform the indicated test on ~60*60 operand types
|
||||
|
||||
|
||||
Reference in New Issue
Block a user