Skip to content
Snippets Groups Projects
Commit dc61d9a3 authored by Martin Nolte's avatar Martin Nolte
Browse files

Merge branch 'bugfix/disableCopyMove-empty-args' into 'master'

fix disableCopyMove for empty arguments

See merge request dune-common!383
parents 683d8741 a7e63576
No related branches found
No related tags found
No related merge requests found
......@@ -256,6 +256,8 @@ dune_add_test(SOURCES to_unique_ptrtest.cc
dune_add_test(SOURCES tupleutilitytest.cc)
dune_add_test(SOURCES typeutilitytest.cc)
dune_add_test(SOURCES typelisttest.cc
LINK_LIBRARIES dunecommon)
......
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#if HAVE_CONFIG_H
#include "config.h"
#endif
#include <type_traits>
#include <dune/common/typeutilities.hh>
//////////////////////////////////////////////////////////////////////
//
// check disableCopyMove
//
struct Foo {
template< class ...Args, Dune::disableCopyMove< Foo, Args ... > = 0 >
Foo( Args&& ... )
{}
Foo( const Foo& ) = delete;
Foo( Foo&& ) = delete;
};
static_assert( std::is_default_constructible< Foo >::value, "Foo is not default constructible." );
static_assert( not std::is_copy_constructible< Foo >::value, "Foo is copy constructible." );
static_assert( not std::is_move_constructible< Foo >::value, "Foo is move constructible." );
int main()
{}
......@@ -17,6 +17,19 @@ namespace Dune {
*/
namespace Impl
{
template<class This, class... T>
struct disableCopyMoveHelper : public std::is_base_of<This, std::tuple_element_t<0, std::tuple<std::decay_t<T>...>>>
{};
template<class This>
struct disableCopyMoveHelper<This> : public std::false_type
{};
} // namespace Impl
/**
* \brief Helper to disable constructor as copy and move constructor
......@@ -27,9 +40,7 @@ namespace Dune {
* overload set for copy and move constructor or assignment.
*/
template<class This, class... T>
using disableCopyMove = typename std::enable_if<
(not(std::is_same<This, typename std::tuple_element<0, std::tuple<typename std::decay<T>::type...> >::type >::value)
and not(std::is_base_of<This, typename std::tuple_element<0, std::tuple<typename std::decay<T>::type...> >::type >::value)), int>::type;
using disableCopyMove = std::enable_if_t< not Impl::disableCopyMoveHelper<This, T...>::value, int>;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment