Skip to content

Commit

Permalink
Moved is_trivially_relocatable for std::tuple to own file
Browse files Browse the repository at this point in the history
  • Loading branch information
OleErikPeistorpet committed May 26, 2024
1 parent 7736266 commit 6d637d4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 11 deletions.
7 changes: 1 addition & 6 deletions optimize_ext/default.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)


// std:: unique_ptr, shared_ptr, weak_ptr, basic_string, pair, tuple
// std:: unique_ptr, shared_ptr, weak_ptr, basic_string, pair
// boost:: intrusive_ptr, local_shared_ptr, circular_buffer, variant, polymorphic_allocator

/** @file
Expand All @@ -14,7 +14,6 @@
#include "../auxi/core_util.h"

#include <memory>
#include <tuple>

#if __has_include(<boost/config.hpp>)
#define OEL_HAS_BOOST 1
Expand Down Expand Up @@ -92,8 +91,4 @@ template< typename T, typename U >
struct is_trivially_relocatable< std::pair<T, U> >
: std::conjunction< is_trivially_relocatable<T>, is_trivially_relocatable<U> > {};

template< typename... Ts >
struct is_trivially_relocatable< std::tuple<Ts...> >
: std::conjunction< is_trivially_relocatable<Ts>... > {};

}
22 changes: 22 additions & 0 deletions optimize_ext/std_tuple.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once

// Distributed under 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)


/** @file
* @brief Must be included manually in user code
*/

#include "../auxi/core_util.h"

#include <tuple>

namespace oel
{

template< typename... Ts >
struct is_trivially_relocatable< std::tuple<Ts...> >
: std::conjunction< is_trivially_relocatable<Ts>... > {};

}
14 changes: 9 additions & 5 deletions unit_test/util_gtest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include "test_classes.h"
#include "dynarray.h"
#include "optimize_ext/std_tuple.h"
#include "optimize_ext/std_variant.h"

#include "gtest/gtest.h"
#include <list>
Expand All @@ -14,16 +16,18 @@

namespace
{
static_assert(oel::is_trivially_relocatable< std::pair<int *, std::unique_ptr<int>> >());
static_assert(oel::is_trivially_relocatable< std::tuple<std::unique_ptr<double>> >());
static_assert(oel::is_trivially_relocatable< std::tuple<> >::value);

struct NonTrivialDestruct
{
~NonTrivialDestruct() { ; }
};

static_assert( !oel::is_trivially_relocatable< std::tuple<int, NonTrivialDestruct, int> >() );
static_assert(oel::is_trivially_relocatable< std::pair<int *, std::unique_ptr<int>> >::value);
static_assert(oel::is_trivially_relocatable< std::tuple<std::unique_ptr<double>> >::value);
static_assert(oel::is_trivially_relocatable< std::tuple<> >::value);
static_assert( !oel::is_trivially_relocatable< std::tuple<int, NonTrivialDestruct, int> >::value );

static_assert(oel::is_trivially_relocatable< std::variant< std::unique_ptr<double>, int > >::value);
static_assert( !oel::is_trivially_relocatable< std::variant<NonTrivialDestruct> >::value );

#if (defined _CPPLIB_VER or defined _LIBCPP_VERSION or defined __GLIBCXX__) and !_GLIBCXX_USE_CXX11_ABI
static_assert(oel::is_trivially_relocatable< std::string >::value);
Expand Down

0 comments on commit 6d637d4

Please sign in to comment.