Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r82087 - in sandbox/static_vector: boost/container boost/container/detail examples test
From: adam.wulkiewicz_at_[hidden]
Date: 2012-12-18 19:13:42


Author: awulkiew
Date: 2012-12-18 19:13:41 EST (Tue, 18 Dec 2012)
New Revision: 82087
URL: http://svn.boost.org/trac/boost/changeset/82087

Log:
static_vector::copy() moved to detail::static_vector::copy().
Added example measuring time of assign() calls.
Added:
   sandbox/static_vector/boost/container/detail/
   sandbox/static_vector/boost/container/detail/static_vector_util.hpp (contents, props changed)
   sandbox/static_vector/examples/
   sandbox/static_vector/examples/times.cpp (contents, props changed)
Text files modified:
   sandbox/static_vector/boost/container/static_vector.hpp | 57 +++++++++++++++++++++++----------------
   sandbox/static_vector/test/static_vector.cpp | 4 +-
   2 files changed, 35 insertions(+), 26 deletions(-)

Added: sandbox/static_vector/boost/container/detail/static_vector_util.hpp
==============================================================================
--- (empty file)
+++ sandbox/static_vector/boost/container/detail/static_vector_util.hpp 2012-12-18 19:13:41 EST (Tue, 18 Dec 2012)
@@ -0,0 +1,84 @@
+// Boost.Container
+//
+// StaticVector details
+//
+// Copyright (c) 2012 Adam Wulkiewicz, Lodz, Poland.
+// Copyright (c) 2011-2012 Andrew Hundt.
+//
+// Use, modification and distribution is subject to the Boost Software License,
+// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef BOOST_CONTAINER_DETAIL_STATIC_VECTOR_UTIL_HPP
+#define BOOST_CONTAINER_DETAIL_STATIC_VECTOR_UTIL_HPP
+
+#include <cstring>
+#include <memory>
+
+#include <boost/mpl/if.hpp>
+#include <boost/mpl/and.hpp>
+#include <boost/mpl/or.hpp>
+#include <boost/mpl/int.hpp>
+
+#include <boost/type_traits/remove_const.hpp>
+#include <boost/type_traits/has_trivial_assign.hpp>
+#include <boost/type_traits/has_trivial_copy.hpp>
+#include <boost/type_traits/has_trivial_constructor.hpp>
+#include <boost/type_traits/has_trivial_destructor.hpp>
+#include <boost/type_traits/has_nothrow_constructor.hpp>
+#include <boost/type_traits/has_nothrow_copy.hpp>
+#include <boost/type_traits/has_nothrow_assign.hpp>
+//#include <boost/type_traits/has_nothrow_destructor.hpp>
+
+#include <boost/iterator/iterator_traits.hpp>
+
+namespace boost { namespace container { namespace detail { namespace static_vector {
+
+template <typename I, typename O>
+struct are_corresponding_pointers :
+ ::boost::mpl::and_<
+ ::boost::is_same<
+ ::boost::remove_const<
+ typename ::boost::iterator_value<I>::type
+ >,
+ ::boost::remove_const<
+ typename ::boost::iterator_value<O>::type
+ >
+ >,
+ ::boost::is_pointer<I>,
+ ::boost::is_pointer<O>
+ >
+{};
+
+template <typename V>
+inline void copy_dispatch(const V * first, const V * last, V * dst,
+ boost::mpl::bool_<true> const& /*use_memcpy*/)
+{
+ ::memcpy(dst, first, sizeof(V) * std::distance(first, last));
+}
+
+template <typename I, typename O>
+inline void copy_dispatch(I first, I last, O dst,
+ boost::mpl::bool_<false> const& /*use_memcpy*/)
+{
+ std::copy(first, last, dst); // may throw
+}
+
+template <typename I, typename O>
+inline void copy(I first, I last, O dst)
+{
+ namespace bm = ::boost::mpl;
+ typedef typename
+ bm::and_<
+ are_corresponding_pointers<I, O>,
+ has_trivial_assign<
+ typename ::boost::iterator_value<O>::type
+ >
+ >::type use_memcpy;
+
+ copy_dispatch(first, last, dst, use_memcpy()); // may throw
+}
+
+}}}} // namespace boost::container::detail::static_vector
+
+#endif // BOOST_CONTAINER_DETAIL_STATIC_VECTOR_UTIL_HPP

Modified: sandbox/static_vector/boost/container/static_vector.hpp
==============================================================================
--- sandbox/static_vector/boost/container/static_vector.hpp (original)
+++ sandbox/static_vector/boost/container/static_vector.hpp 2012-12-18 19:13:41 EST (Tue, 18 Dec 2012)
@@ -10,9 +10,12 @@
 #ifndef BOOST_CONTAINER_STATIC_VECTOR_HPP
 #define BOOST_CONTAINER_STATIC_VECTOR_HPP
 
+#include <boost/container/detail/static_vector_util.hpp>
+
 #include <cstddef>
 #include <stdexcept>
 
+#include <boost/assert.hpp>
 #include <boost/config.hpp>
 #include <boost/swap.hpp>
 #include <boost/integer.hpp>
@@ -24,6 +27,7 @@
 #include <boost/mpl/and.hpp>
 #include <boost/mpl/or.hpp>
 
+#include <boost/type_traits/is_unsigned.hpp>
 #include <boost/type_traits/is_same.hpp>
 #include <boost/type_traits/alignment_of.hpp>
 #include <boost/type_traits/aligned_storage.hpp>
@@ -693,33 +697,38 @@
     // copy
 
     template <typename Iterator>
- void copy(Iterator first, Iterator last, iterator dst)
+ inline static void copy(Iterator first, Iterator last, iterator dst)
     {
- typedef typename
- mpl::and_<
- has_trivial_assign<value_type>,
- mpl::or_<
- is_same<Iterator, value_type *>,
- is_same<Iterator, const value_type *>
- >
- >::type
- use_memcpy;
-
- this->copy_dispatch(first, last, dst, use_memcpy()); // may throw
- }
+ namespace sv = detail::static_vector;
+ sv::copy(first, last, dst);
 
- void copy_dispatch(const value_type * first, const value_type * last, value_type * dst,
- boost::mpl::bool_<true> const& /*use_memcpy*/)
- {
- ::memcpy(dst, first, sizeof(value_type) * std::distance(first, last));
- }
+ //detail::static_vector::copy(first, last, dst);
 
- template <typename Iterator>
- void copy_dispatch(Iterator first, Iterator last, value_type * dst,
- boost::mpl::bool_<false> const& /*use_memcpy*/)
- {
- std::copy(first, last, dst); // may throw
- }
+ //typedef typename
+ // mpl::and_<
+ // has_trivial_assign<value_type>,
+ // mpl::or_<
+ // is_same<Iterator, value_type *>,
+ // is_same<Iterator, const value_type *>
+ // >
+ // >::type
+ //use_memcpy;
+ //
+ //copy_dispatch(first, last, dst, use_memcpy()); // may throw
+ }
+
+ //inline static void copy_dispatch(const value_type * first, const value_type * last, value_type * dst,
+ // boost::mpl::bool_<true> const& /*use_memcpy*/)
+ //{
+ // ::memcpy(dst, first, sizeof(value_type) * std::distance(first, last));
+ //}
+
+ //template <typename Iterator>
+ //inline static void copy_dispatch(Iterator first, Iterator last, value_type * dst,
+ // boost::mpl::bool_<false> const& /*use_memcpy*/)
+ //{
+ // std::copy(first, last, dst); // may throw
+ //}
 
     // uninitialized_copy
 

Added: sandbox/static_vector/examples/times.cpp
==============================================================================
--- (empty file)
+++ sandbox/static_vector/examples/times.cpp 2012-12-18 19:13:41 EST (Tue, 18 Dec 2012)
@@ -0,0 +1,85 @@
+#include<boost/container/static_vector.hpp>
+
+#include <boost/timer.hpp>
+#include <fstream>
+#include <iostream>
+
+using namespace boost::container;
+
+template <typename T>
+class value
+{
+public:
+ explicit value(T a = 0) : aa(a) {}
+ value(value const& v) : aa(v.aa) {}
+ value & operator=(value const& v) { aa = v.aa; return *this; }
+ ~value() {}
+ bool operator==(value const& v) const { return aa == v.aa; }
+ operator T () { return aa; }
+private:
+ T aa;
+};
+
+template <typename T>
+class value2
+{
+public:
+ explicit value2(T a = 0) : aa(a) {}
+ bool operator==(value2 const& v) const { return aa == v.aa; }
+ operator T () { return aa; }
+private:
+ T aa;
+};
+
+template <typename V, size_t N>
+size_t test(size_t count)
+{
+ static_vector<V, N> sv;
+ for ( size_t i = 0 ; i < sv.capacity() ; ++i)
+ sv.push_back(V(i));
+
+ static_vector<V, N> sv2;
+ size_t dummy = 0;
+ for ( size_t i = 0 ; i < count ; ++i )
+ {
+ sv2.assign(sv.begin(), sv.end());
+ dummy += sv2[0];
+ }
+
+ return dummy;
+};
+
+int main()
+{
+#ifdef NDEBUG
+ size_t count = 5000000;
+#else
+ size_t count = 50000;
+#endif
+
+ std::fstream f("foobar.txt", std::ios::in | std::ios::out);
+ f >> count;
+
+ for(;;)
+ {
+ {
+ boost::timer tim;
+ size_t dummy = test<size_t, 1000>(count);
+ double t = tim.elapsed();
+ std::cout << t << " " << dummy << std::endl;
+ }
+ {
+ boost::timer tim;
+ size_t dummy = test<value<size_t>, 1000>(count);
+ double t = tim.elapsed();
+ std::cout << t << " " << dummy << std::endl;
+ }
+ {
+ boost::timer tim;
+ size_t dummy = test<value2<size_t>, 1000>(count);
+ double t = tim.elapsed();
+ std::cout << t << " " << dummy << std::endl;
+ }
+ }
+
+}
\ No newline at end of file

Modified: sandbox/static_vector/test/static_vector.cpp
==============================================================================
--- sandbox/static_vector/test/static_vector.cpp (original)
+++ sandbox/static_vector/test/static_vector.cpp 2012-12-18 19:13:41 EST (Tue, 18 Dec 2012)
@@ -7,6 +7,8 @@
 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
 // http://www.boost.org/LICENSE_1_0.txt)
 
+#include <boost/container/static_vector.hpp>
+
 #include <boost/test/included/test_exec_monitor.hpp>
 #include <boost/test/impl/execution_monitor.ipp>
 
@@ -14,8 +16,6 @@
 #include <list>
 #include <boost/shared_ptr.hpp>
 
-#include <boost/container/static_vector.hpp>
-
 using namespace boost::container;
 
 class value_ndc


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