Skip to content

Commit aca6253

Browse files
awulkiewtinko92
authored andcommitted
[index] Use memcpy and memmove only if T is_trivially_copyable.
In C++03 mimic the trait with has_trivial_copy, has_trivial_assign and has_trivial_destructor.
1 parent b032016 commit aca6253

File tree

1 file changed

+38
-12
lines changed

1 file changed

+38
-12
lines changed

include/boost/geometry/index/detail/varray_detail.hpp

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// varray details
44
//
5-
// Copyright (c) 2012-2015 Adam Wulkiewicz, Lodz, Poland.
5+
// Copyright (c) 2012-2020 Adam Wulkiewicz, Lodz, Poland.
66
// Copyright (c) 2011-2013 Andrew Hundt.
77
//
88
// Use, modification and distribution is subject to the Boost Software License,
@@ -17,6 +17,8 @@
1717
#include <memory>
1818
#include <limits>
1919

20+
#include <boost/config.hpp>
21+
2022
#include <boost/mpl/if.hpp>
2123
#include <boost/mpl/and.hpp>
2224
#include <boost/mpl/or.hpp>
@@ -36,8 +38,11 @@
3638
//#include <boost/type_traits/has_nothrow_assign.hpp>
3739
//#include <boost/type_traits/has_nothrow_destructor.hpp>
3840

41+
#if ! defined(BOOST_NO_CXX11_HDR_TYPE_TRAITS)
42+
#include <type_traits>
43+
#endif
44+
3945
#include <boost/detail/no_exceptions_support.hpp>
40-
#include <boost/config.hpp>
4146
#include <boost/move/move.hpp>
4247
#include <boost/core/addressof.hpp>
4348
#include <boost/iterator/iterator_traits.hpp>
@@ -53,7 +58,28 @@
5358
#include <boost/container/vector.hpp>
5459
#endif // BOOST_GEOMETRY_INDEX_DETAIL_VARRAY_ENABLE_VECTOR_OPTIMIZATION && !BOOST_NO_EXCEPTIONS
5560

56-
namespace boost { namespace geometry { namespace index { namespace detail { namespace varray_detail {
61+
namespace boost { namespace geometry { namespace index { namespace detail { namespace varray_detail
62+
{
63+
64+
#if ! defined(BOOST_NO_CXX11_HDR_TYPE_TRAITS)
65+
66+
using std::is_trivially_copyable;
67+
68+
#else
69+
70+
template <typename T>
71+
struct is_trivially_copyable
72+
: boost::integral_constant
73+
<
74+
bool,
75+
boost::has_trivial_copy<T>::value
76+
&& boost::has_trivial_assign<T>::value
77+
&& boost::has_trivial_destructor<T>::value
78+
>
79+
{};
80+
81+
#endif
82+
5783

5884
template <typename I>
5985
struct are_elements_contiguous : boost::is_pointer<I>
@@ -164,7 +190,7 @@ template <typename I>
164190
void destroy(I first, I last)
165191
{
166192
typedef typename boost::iterator_value<I>::type value_type;
167-
destroy_dispatch(first, last, has_trivial_destructor<value_type>());
193+
destroy_dispatch(first, last, boost::has_trivial_destructor<value_type>());
168194
}
169195

170196
// destroy(I)
@@ -186,7 +212,7 @@ template <typename I>
186212
void destroy(I pos)
187213
{
188214
typedef typename boost::iterator_value<I>::type value_type;
189-
destroy_dispatch(pos, has_trivial_destructor<value_type>());
215+
destroy_dispatch(pos, boost::has_trivial_destructor<value_type>());
190216
}
191217

192218
// copy(I, I, O)
@@ -215,7 +241,7 @@ inline O copy(I first, I last, O dst)
215241
typedef typename
216242
::boost::mpl::and_<
217243
are_corresponding<I, O>,
218-
::boost::has_trivial_assign<
244+
is_trivially_copyable<
219245
typename ::boost::iterator_value<O>::type
220246
>
221247
>::type
@@ -253,7 +279,7 @@ F uninitialized_copy(I first, I last, F dst)
253279
typedef typename
254280
::boost::mpl::and_<
255281
are_corresponding<I, F>,
256-
::boost::has_trivial_copy<
282+
is_trivially_copyable<
257283
typename ::boost::iterator_value<F>::type
258284
>
259285
>::type
@@ -308,7 +334,7 @@ O uninitialized_move(I first, I last, O dst)
308334
typedef typename
309335
::boost::mpl::and_<
310336
are_corresponding<I, O>,
311-
::boost::has_trivial_copy<
337+
is_trivially_copyable<
312338
typename ::boost::iterator_value<O>::type
313339
>
314340
>::type
@@ -348,7 +374,7 @@ O move(I first, I last, O dst)
348374
typedef typename
349375
::boost::mpl::and_<
350376
are_corresponding<I, O>,
351-
::boost::has_trivial_assign<
377+
is_trivially_copyable<
352378
typename ::boost::iterator_value<O>::type
353379
>
354380
>::type
@@ -387,7 +413,7 @@ BDO move_backward(BDI first, BDI last, BDO dst)
387413
typedef typename
388414
::boost::mpl::and_<
389415
are_corresponding<BDI, BDO>,
390-
::boost::has_trivial_assign<
416+
is_trivially_copyable<
391417
typename ::boost::iterator_value<BDO>::type
392418
>
393419
>::type
@@ -561,7 +587,7 @@ void construct(DisableTrivialInit const&,
561587
typedef typename
562588
::boost::mpl::and_<
563589
is_corresponding_value<I, P>,
564-
::boost::has_trivial_copy<P>
590+
is_trivially_copyable<P>
565591
>::type
566592
use_memcpy;
567593

@@ -668,7 +694,7 @@ void assign(I pos, V const& v)
668694
typedef typename
669695
::boost::mpl::and_<
670696
is_corresponding_value<I, V>,
671-
::boost::has_trivial_assign<V>
697+
is_trivially_copyable<V>
672698
>::type
673699
use_memcpy;
674700

0 commit comments

Comments
 (0)