|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r73364 - in sandbox/coerce: boost/coerce boost/coerce/detail libs/coerce/test
From: vexocide_at_[hidden]
Date: 2011-07-25 17:18:44
Author: vexocide
Date: 2011-07-25 17:18:43 EDT (Mon, 25 Jul 2011)
New Revision: 73364
URL: http://svn.boost.org/trac/boost/changeset/73364
Log:
Added tag support to reserve
Text files modified:
sandbox/coerce/boost/coerce/detail/karma.hpp | 2
sandbox/coerce/boost/coerce/reserve.hpp | 135 ++++++++++++++++++++++++++-------------
sandbox/coerce/libs/coerce/test/reserve.cpp | 89 ++++++++++++++++++-------
3 files changed, 152 insertions(+), 74 deletions(-)
Modified: sandbox/coerce/boost/coerce/detail/karma.hpp
==============================================================================
--- sandbox/coerce/boost/coerce/detail/karma.hpp (original)
+++ sandbox/coerce/boost/coerce/detail/karma.hpp 2011-07-25 17:18:43 EDT (Mon, 25 Jul 2011)
@@ -27,7 +27,7 @@
static inline bool
call(Target & target, Source const & source, Tag const & tag) {
detail::call_reserve(
- target, traits::reserve_size<Source>::call(source));
+ target, traits::reserve_size<Source, Tag>::call(source, tag));
typename traits::sequence<Target>::type iterator =
traits::sequence<Target>::back_inserter(target);
Modified: sandbox/coerce/boost/coerce/reserve.hpp
==============================================================================
--- sandbox/coerce/boost/coerce/reserve.hpp (original)
+++ sandbox/coerce/boost/coerce/reserve.hpp 2011-07-25 17:18:43 EDT (Mon, 25 Jul 2011)
@@ -12,8 +12,11 @@
#endif
#include <boost/coerce/detail/reserve.hpp>
+#include <boost/coerce/precision.hpp>
+#include <boost/coerce/tag.hpp>
#include <boost/config.hpp>
+#include <boost/integer/static_log2.hpp>
#include <boost/limits.hpp>
#include <boost/optional.hpp>
@@ -21,101 +24,139 @@
namespace boost { namespace coerce { namespace traits {
- template <typename T>
+ template <typename T, typename Tag>
struct reserve_size_impl {
BOOST_STATIC_CONSTANT(std::size_t, value = 0);
};
template <>
- struct reserve_size_impl<char> {
+ struct reserve_size_impl<char, tag::none> {
BOOST_STATIC_CONSTANT(std::size_t, value = 1);
};
template <>
- struct reserve_size_impl<wchar_t> {
+ struct reserve_size_impl<wchar_t, tag::none> {
BOOST_STATIC_CONSTANT(std::size_t, value = 1);
};
- template <typename T>
+ template <typename T, typename Tag>
struct reserve_size_impl_integral {
+ BOOST_STATIC_CONSTANT(std::size_t, value = 0);
+ };
+
+ template <typename T>
+ struct reserve_size_impl_integral<T, tag::none> {
BOOST_STATIC_CONSTANT(std::size_t, value =
std::numeric_limits<T>::is_signed +
1 +
std::numeric_limits<T>::digits10);
};
- template <>
- struct reserve_size_impl<int>
- : reserve_size_impl_integral<int> { };
+ template <typename T, unsigned Radix>
+ struct reserve_size_impl_integral<T, tag::base<Radix> > {
+ BOOST_STATIC_CONSTANT(std::size_t, value =
+ 1 +
+ std::numeric_limits<T>::digits / static_log2<Radix>::value);
+ };
- template <>
- struct reserve_size_impl<short>
- : reserve_size_impl_integral<short> { };
+ template <typename T>
+ struct reserve_size_impl_integral<T, tag::bin> {
+ BOOST_STATIC_CONSTANT(std::size_t, value =
+ 1 +
+ std::numeric_limits<T>::digits);
+ };
- template <>
- struct reserve_size_impl<long>
- : reserve_size_impl_integral<long> { };
+ template <typename T>
+ struct reserve_size_impl_integral<T, tag::oct> {
+ BOOST_STATIC_CONSTANT(std::size_t, value =
+ 1 +
+ std::numeric_limits<T>::digits / 3);
+ };
- template <>
- struct reserve_size_impl<unsigned int>
- : reserve_size_impl_integral<unsigned int> { };
+ template <typename T>
+ struct reserve_size_impl_integral<T, tag::hex> {
+ BOOST_STATIC_CONSTANT(std::size_t, value =
+ 1 +
+ std::numeric_limits<T>::digits / 4);
+ };
- template <>
- struct reserve_size_impl<unsigned short>
- : reserve_size_impl_integral<unsigned short> { };
+ template <typename Tag>
+ struct reserve_size_impl<int, Tag>
+ : reserve_size_impl_integral<int, Tag> { };
- template <>
- struct reserve_size_impl<unsigned long>
- : reserve_size_impl_integral<unsigned long> { };
+ template <typename Tag>
+ struct reserve_size_impl<short, Tag>
+ : reserve_size_impl_integral<short, Tag> { };
-#ifdef BOOST_HAS_LONG_LONG
+ template <typename Tag>
+ struct reserve_size_impl<long, Tag>
+ : reserve_size_impl_integral<long, Tag> { };
- template <>
- struct reserve_size_impl<boost::long_long_type>
- : reserve_size_impl_integral<boost::long_long_type> { };
+ template <typename Tag>
+ struct reserve_size_impl<unsigned int, Tag>
+ : reserve_size_impl_integral<unsigned int, Tag> { };
- template <>
- struct reserve_size_impl<boost::ulong_long_type>
- : reserve_size_impl_integral<boost::ulong_long_type> { };
+ template <typename Tag>
+ struct reserve_size_impl<unsigned short, Tag>
+ : reserve_size_impl_integral<unsigned short, Tag> { };
+
+ template <typename Tag>
+ struct reserve_size_impl<unsigned long, Tag>
+ : reserve_size_impl_integral<unsigned long, Tag> { };
+
+#ifdef BOOST_HAS_LONG_LONG
+
+ template <typename Tag>
+ struct reserve_size_impl<boost::long_long_type, Tag>
+ : reserve_size_impl_integral<boost::long_long_type, Tag> { };
+
+ template <typename Tag>
+ struct reserve_size_impl<boost::ulong_long_type, Tag>
+ : reserve_size_impl_integral<boost::ulong_long_type, Tag> { };
#endif // BOOST_HAS_LONG_LONG
- template <typename T>
+ template <typename T, typename Tag>
struct reserve_size_impl_floating_point {
+ BOOST_STATIC_CONSTANT(std::size_t, value = 0);
+ };
+
+ template <typename T>
+ struct reserve_size_impl_floating_point<T, tag::none> {
BOOST_STATIC_CONSTANT(std::size_t, value =
std::numeric_limits<T>::is_signed +
8 +
- std::numeric_limits<T>::digits10);
+ precision<T>::value);
};
- template <>
- struct reserve_size_impl<float>
- : reserve_size_impl_floating_point<float> { };
+ template <typename Tag>
+ struct reserve_size_impl<float, Tag>
+ : reserve_size_impl_floating_point<float, Tag> { };
- template <>
- struct reserve_size_impl<double>
- : reserve_size_impl_floating_point<double> { };
+ template <typename Tag>
+ struct reserve_size_impl<double, Tag>
+ : reserve_size_impl_floating_point<double, Tag> { };
- template <>
- struct reserve_size_impl<long double>
- : reserve_size_impl_floating_point<long double> { };
+ template <typename Tag>
+ struct reserve_size_impl<long double, Tag>
+ : reserve_size_impl_floating_point<long double, Tag> { };
template <>
- struct reserve_size_impl<bool> {
+ struct reserve_size_impl<bool, tag::none> {
BOOST_STATIC_CONSTANT(std::size_t, value = 5);
};
- template <typename T>
- struct reserve_size_impl<boost::optional<T> >
- : reserve_size_impl<T> { };
+ template <typename T, typename Tag>
+ struct reserve_size_impl<boost::optional<T>, Tag>
+ : reserve_size_impl<T, Tag> { };
- template <typename T, typename Enable = void>
+ template <typename T, typename Tag, typename Enable = void>
struct reserve_size {
typedef std::size_t type;
static inline type
- call(T const &) {
- return reserve_size_impl<T>::value;
+ call(T const &, Tag const &) {
+ return reserve_size_impl<T, Tag>::value;
}
};
Modified: sandbox/coerce/libs/coerce/test/reserve.cpp
==============================================================================
--- sandbox/coerce/libs/coerce/test/reserve.cpp (original)
+++ sandbox/coerce/libs/coerce/test/reserve.cpp 2011-07-25 17:18:43 EDT (Mon, 25 Jul 2011)
@@ -16,38 +16,75 @@
#include <vector>
BOOST_AUTO_TEST_CASE(reserve_size) {
- using boost::coerce::traits::reserve_size;
-
- BOOST_CHECK_GT(reserve_size<char>::call('\0'), 0u);
- BOOST_CHECK_GT(reserve_size<wchar_t>::call(L'\0'), 0u);
- short const test_short = 0;
- BOOST_CHECK_GT(reserve_size<short>::call(test_short), 0u);
- BOOST_CHECK_GT(reserve_size<int>::call(0), 0u);
- BOOST_CHECK_GT(reserve_size<long>::call(0l), 0u);
- unsigned short const test_unsigned_short = 0u;
- BOOST_CHECK_GT(reserve_size<unsigned short>::call(
- test_unsigned_short), 0u);
- BOOST_CHECK_GT(reserve_size<unsigned int>::call(0u), 0u);
- BOOST_CHECK_GT(reserve_size<unsigned long>::call(0ul), 0u);
- BOOST_CHECK_GT(reserve_size<float>::call(0.0f), 0u);
- BOOST_CHECK_GT(reserve_size<double>::call(0.0), 0u);
- BOOST_CHECK_GT(reserve_size<long double>::call(0.0l), 0u);
- BOOST_CHECK_GT(reserve_size<bool>::call(false), 0u);
-
- BOOST_CHECK_GT(reserve_size<boost::optional<char> >::call(
- boost::optional<char>('\0')), 0u);
+ using namespace boost;
+
+ BOOST_CHECK_GT(
+ (coerce::traits::reserve_size<char, coerce::tag::none>::call(
+ '\0', coerce::tag::none())), 0u);
+ BOOST_CHECK_GT(
+ (coerce::traits::reserve_size<wchar_t, coerce::tag::none>::call(
+ L'\0', coerce::tag::none())), 0u);
+ BOOST_CHECK_GT(
+ (coerce::traits::reserve_size<short, coerce::tag::none>::call(
+ static_cast<short const>(0), coerce::tag::none())), 0u);
+ BOOST_CHECK_GT(
+ (coerce::traits::reserve_size<int, coerce::tag::none>::call(
+ 0, coerce::tag::none())), 0u);
+ BOOST_CHECK_GT(
+ (coerce::traits::reserve_size<long, coerce::tag::none>::call(
+ 0l, coerce::tag::none())), 0u);
+ BOOST_CHECK_GT(
+ (coerce::traits::reserve_size<unsigned short, coerce::tag::none>::call(
+ static_cast<unsigned short const>(0), coerce::tag::none())), 0u);
+ BOOST_CHECK_GT(
+ (coerce::traits::reserve_size<unsigned int, coerce::tag::none>::call(
+ 0u, coerce::tag::none())), 0u);
+ BOOST_CHECK_GT(
+ (coerce::traits::reserve_size<unsigned long, coerce::tag::none>::call(
+ 0ul, coerce::tag::none())), 0u);
+ BOOST_CHECK_GT(
+ (coerce::traits::reserve_size<float, coerce::tag::none>::call(
+ 0.0f, coerce::tag::none())), 0u);
+ BOOST_CHECK_GT(
+ (coerce::traits::reserve_size<double, coerce::tag::none>::call(
+ 0.0, coerce::tag::none())), 0u);
+ BOOST_CHECK_GT(
+ (coerce::traits::reserve_size<long double, coerce::tag::none>::call(
+ 0.0l, coerce::tag::none())), 0u);
+ BOOST_CHECK_GT(
+ (coerce::traits::reserve_size<bool, coerce::tag::none>::call(
+ false, coerce::tag::none())), 0u);
+
+ BOOST_CHECK_GT(
+ (coerce::traits::reserve_size<
+ boost::optional<char>, coerce::tag::none
+ >::call(
+ boost::optional<char>('\0'), coerce::tag::none())), 0u);
+
+ BOOST_CHECK_GT(
+ (coerce::traits::reserve_size<unsigned, coerce::tag::base<10> >::call(
+ 0u, coerce::tag::base<10>())), 0u);
+ BOOST_CHECK_GT(
+ (coerce::traits::reserve_size<unsigned, coerce::tag::bin>::call(
+ 0u, coerce::tag::bin())), 0u);
+ BOOST_CHECK_GT(
+ (coerce::traits::reserve_size<unsigned, coerce::tag::oct>::call(
+ 0u, coerce::tag::oct())), 0u);
+ BOOST_CHECK_GT(
+ (coerce::traits::reserve_size<unsigned, coerce::tag::hex>::call(
+ 0u, coerce::tag::hex())), 0u);
}
BOOST_AUTO_TEST_CASE(has_reserve) {
- using boost::coerce::detail::has_reserve;
+ using namespace boost;
- BOOST_CHECK(!has_reserve<void>::type());
+ BOOST_CHECK(!coerce::detail::has_reserve<void>::type());
- BOOST_CHECK(has_reserve<std::string>::type());
- BOOST_CHECK(has_reserve<std::wstring>::type());
+ BOOST_CHECK(coerce::detail::has_reserve<std::string>::type());
+ BOOST_CHECK(coerce::detail::has_reserve<std::wstring>::type());
- BOOST_CHECK(has_reserve<std::vector<char> >::type());
- BOOST_CHECK(has_reserve<std::vector<wchar_t> >::type());
+ BOOST_CHECK(coerce::detail::has_reserve<std::vector<char> >::type());
+ BOOST_CHECK(coerce::detail::has_reserve<std::vector<wchar_t> >::type());
}
// TODO, call_reserve
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk