Remove "operator value_type() const noexcept" from buffers. Make the buffer ctor explicit. Buffers were requested by people who do not want automatic conversions because they want full control over conversions, and are very concerned about "efficiency".

Add "operator value_type() const noexcept" to the endian arithmetic types. These types are used by people who do want fully automatic conversions. The arithmetic types need to be drop-in replacements for the built-in arithmetic types for these users.
This commit is contained in:
Beman
2014-11-18 14:33:31 -05:00
parent 221ad3c585
commit 61d9046348
3 changed files with 26 additions and 27 deletions

View File

@ -37,9 +37,6 @@
#include <boost/config.hpp>
#include <boost/predef/detail/endian_compat.h>
#include <boost/endian/conversion.hpp>
#define BOOST_ENDIAN_MINIMAL_COVER_OPERATORS
#include <boost/endian/detail/cover_operators.hpp>
#undef BOOST_ENDIAN_MINIMAL_COVER_OPERATORS
#include <boost/type_traits/is_signed.hpp>
#include <boost/cstdint.hpp>
#include <boost/static_assert.hpp>
@ -61,12 +58,6 @@
# define BOOST_ENDIAN_NO_CTORS
# endif
# ifndef BOOST_ENDIAN_EXPLICIT_CTORS
# define BOOST_ENDIAN_EXPLICIT_OPT
# else
# define BOOST_ENDIAN_EXPLICIT_OPT explicit
# endif
//---------------------------------- synopsis ----------------------------------------//
namespace boost
@ -342,7 +333,7 @@ namespace endian
typedef T value_type;
# ifndef BOOST_ENDIAN_NO_CTORS
endian_buffer() BOOST_ENDIAN_DEFAULT_CONSTRUCT
BOOST_ENDIAN_EXPLICIT_OPT endian_buffer(T val) BOOST_NOEXCEPT
explicit endian_buffer(T val) BOOST_NOEXCEPT
{
# ifdef BOOST_ENDIAN_LOG
if ( endian_log )
@ -361,7 +352,7 @@ namespace endian
detail::store_big_endian<T, n_bits/8>(m_value, val);
return *this;
}
operator T() const BOOST_NOEXCEPT
value_type value() const BOOST_NOEXCEPT
{
# ifdef BOOST_ENDIAN_LOG
if ( endian_log )
@ -383,12 +374,12 @@ namespace endian
typedef float value_type;
# ifndef BOOST_ENDIAN_NO_CTORS
endian_buffer() BOOST_ENDIAN_DEFAULT_CONSTRUCT
BOOST_ENDIAN_EXPLICIT_OPT endian_buffer(value_type val) BOOST_NOEXCEPT
explicit endian_buffer(value_type val) BOOST_NOEXCEPT
{ detail::big_reverse_copy(val, m_value); }
# endif
endian_buffer & operator=(value_type val) BOOST_NOEXCEPT
{ detail::big_reverse_copy(val, m_value); return *this; }
operator value_type() const BOOST_NOEXCEPT
value_type value() const BOOST_NOEXCEPT
{
value_type tmp;
detail::big_reverse_copy(m_value, tmp);
@ -407,12 +398,12 @@ namespace endian
typedef double value_type;
# ifndef BOOST_ENDIAN_NO_CTORS
endian_buffer() BOOST_ENDIAN_DEFAULT_CONSTRUCT
BOOST_ENDIAN_EXPLICIT_OPT endian_buffer(value_type val) BOOST_NOEXCEPT
explicit endian_buffer(value_type val) BOOST_NOEXCEPT
{ detail::big_reverse_copy(val, m_value); }
# endif
endian_buffer & operator=(value_type val) BOOST_NOEXCEPT
{ detail::big_reverse_copy(val, m_value); return *this; }
operator value_type() const BOOST_NOEXCEPT
value_type value() const BOOST_NOEXCEPT
{
value_type tmp;
detail::big_reverse_copy(m_value, tmp);
@ -431,12 +422,12 @@ namespace endian
typedef float value_type;
# ifndef BOOST_ENDIAN_NO_CTORS
endian_buffer() BOOST_ENDIAN_DEFAULT_CONSTRUCT
BOOST_ENDIAN_EXPLICIT_OPT endian_buffer(value_type val) BOOST_NOEXCEPT
explicit endian_buffer(value_type val) BOOST_NOEXCEPT
{ detail::little_reverse_copy(val, m_value); }
# endif
endian_buffer & operator=(value_type val) BOOST_NOEXCEPT
{ detail::little_reverse_copy(val, m_value); return *this; }
operator value_type() const BOOST_NOEXCEPT
value_type value() const BOOST_NOEXCEPT
{
value_type tmp;
detail::little_reverse_copy(m_value, tmp);
@ -455,12 +446,12 @@ namespace endian
typedef double value_type;
# ifndef BOOST_ENDIAN_NO_CTORS
endian_buffer() BOOST_ENDIAN_DEFAULT_CONSTRUCT
BOOST_ENDIAN_EXPLICIT_OPT endian_buffer(value_type val) BOOST_NOEXCEPT
explicit endian_buffer(value_type val) BOOST_NOEXCEPT
{ detail::little_reverse_copy(val, m_value); }
# endif
endian_buffer & operator=(value_type val) BOOST_NOEXCEPT
{ detail::little_reverse_copy(val, m_value); return *this; }
operator value_type() const BOOST_NOEXCEPT
value_type value() const BOOST_NOEXCEPT
{
value_type tmp;
detail::little_reverse_copy(m_value, tmp);
@ -480,7 +471,7 @@ namespace endian
typedef T value_type;
# ifndef BOOST_ENDIAN_NO_CTORS
endian_buffer() BOOST_ENDIAN_DEFAULT_CONSTRUCT
BOOST_ENDIAN_EXPLICIT_OPT endian_buffer(T val) BOOST_NOEXCEPT
explicit endian_buffer(T val) BOOST_NOEXCEPT
{
# ifdef BOOST_ENDIAN_LOG
if ( endian_log )
@ -492,7 +483,7 @@ namespace endian
# endif
endian_buffer & operator=(T val) BOOST_NOEXCEPT
{ detail::store_little_endian<T, n_bits/8>(m_value, val); return *this; }
operator T() const BOOST_NOEXCEPT
value_type value() const BOOST_NOEXCEPT
{
# ifdef BOOST_ENDIAN_LOG
if ( endian_log )
@ -518,7 +509,7 @@ namespace endian
typedef T value_type;
# ifndef BOOST_ENDIAN_NO_CTORS
endian_buffer() BOOST_ENDIAN_DEFAULT_CONSTRUCT
BOOST_ENDIAN_EXPLICIT_OPT endian_buffer(T val) BOOST_NOEXCEPT
explicit endian_buffer(T val) BOOST_NOEXCEPT
{
# ifdef BOOST_ENDIAN_LOG
if ( endian_log )
@ -534,7 +525,7 @@ namespace endian
m_value = ::boost::endian::big_endian_value(val);
return *this;
}
operator T() const BOOST_NOEXCEPT
value_type value() const BOOST_NOEXCEPT
{
# ifdef BOOST_ENDIAN_LOG
if ( endian_log )
@ -559,7 +550,7 @@ namespace endian
typedef T value_type;
# ifndef BOOST_ENDIAN_NO_CTORS
endian_buffer() BOOST_ENDIAN_DEFAULT_CONSTRUCT
BOOST_ENDIAN_EXPLICIT_OPT endian_buffer(T val) BOOST_NOEXCEPT
explicit endian_buffer(T val) BOOST_NOEXCEPT
{
# ifdef BOOST_ENDIAN_LOG
if ( endian_log )
@ -575,7 +566,7 @@ namespace endian
m_value = ::boost::endian::little_endian_value(val);
return *this;
}
operator T() const BOOST_NOEXCEPT
value_type value() const BOOST_NOEXCEPT
{
# ifdef BOOST_ENDIAN_LOG
if ( endian_log )

View File

@ -37,8 +37,8 @@
#include <boost/config.hpp>
#include <boost/predef/detail/endian_compat.h>
#include <boost/endian/conversion.hpp>
#define BOOST_ENDIAN_MINIMAL_COVER_OPERATORS
#include <boost/endian/buffers.hpp>
#define BOOST_ENDIAN_MINIMAL_COVER_OPERATORS
#include <boost/endian/detail/cover_operators.hpp>
#undef BOOST_ENDIAN_MINIMAL_COVER_OPERATORS
#include <boost/type_traits/is_signed.hpp>
@ -263,6 +263,7 @@ namespace endian
# endif
endian & operator=(T val) BOOST_NOEXCEPT
{ detail::store_big_endian<T, n_bits/8>(this->m_value, val); return *this; }
operator value_type() const BOOST_NOEXCEPT { return this->value(); }
};
// unaligned float big endian specialization
@ -280,6 +281,7 @@ namespace endian
# endif
endian & operator=(value_type val) BOOST_NOEXCEPT
{ detail::big_reverse_copy(val, this->m_value); return *this; }
operator value_type() const BOOST_NOEXCEPT { return this->value(); }
};
// unaligned double big endian specialization
@ -297,6 +299,7 @@ namespace endian
# endif
endian & operator=(value_type val) BOOST_NOEXCEPT
{ detail::big_reverse_copy(val, this->m_value); return *this; }
operator value_type() const BOOST_NOEXCEPT { return this->value(); }
};
// unaligned float little endian specialization
@ -314,6 +317,7 @@ namespace endian
# endif
endian & operator=(value_type val) BOOST_NOEXCEPT
{ detail::little_reverse_copy(val, this->m_value); return *this; }
operator value_type() const BOOST_NOEXCEPT { return this->value(); }
};
// unaligned double little endian specialization
@ -331,6 +335,7 @@ namespace endian
# endif
endian & operator=(value_type val) BOOST_NOEXCEPT
{ detail::little_reverse_copy(val, this->m_value); return *this; }
operator value_type() const BOOST_NOEXCEPT { return this->value(); }
};
// unaligned little endian specialization
@ -355,6 +360,7 @@ namespace endian
# endif
endian & operator=(T val) BOOST_NOEXCEPT
{ detail::store_little_endian<T, n_bits/8>(this->m_value, val); return *this; }
operator value_type() const BOOST_NOEXCEPT { return this->value(); }
};
// align::yes specializations; only n_bits == 16/32/64 supported
@ -386,6 +392,7 @@ namespace endian
this->m_value = ::boost::endian::big_endian_value(val);
return *this;
}
operator value_type() const BOOST_NOEXCEPT { return this->value(); }
};
// aligned little endian specialization
@ -414,6 +421,7 @@ namespace endian
this->m_value = ::boost::endian::little_endian_value(val);
return *this;
}
operator value_type() const BOOST_NOEXCEPT { return this->value(); }
};
} // namespace endian

View File

@ -35,7 +35,7 @@ int cpp_main(int, char *[])
x = 1234567890;
cout << " operator==(buffer, built-in)" << endl;
bool b1(x == 1234567890);
// bool b1(x == 1234567890);
// BOOST_TEST(x == 1234567890);
cout << " done" << endl;