Skip to content
Snippets Groups Projects
Commit 73dc8e52 authored by Simon Praetorius's avatar Simon Praetorius Committed by Santiago Ospina De Los Ríos
Browse files

Add deduction guides for TupleVector following those of std::tuple

parent 65585764
No related branches found
No related tags found
2 merge requests!1470Fix wrong variable name to make target hash (2.10),!1435Add deduction guides for TupleVector following those of std::tuple
......@@ -5,6 +5,10 @@ SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
# Master (will become release 2.11)
## C++: Changelog
- Add deduction guides to `TupleVector` analogous to `std::tuple`.
# Release 2.10
## Dependencies
......
......@@ -261,5 +261,33 @@ int main()
constexpr auto numberTupleConstexpr = Dune::makeTupleVector(0.25, 2, 3);
static_assert(sum(numberTupleConstexpr) == 5.25, "Wrong compile time sum!");
{ // CTAD tests
auto tv0 = Dune::TupleVector{};
// test construction with values
static_assert(std::is_same_v<decltype(tv0),Dune::TupleVector<>>);
auto tv1 = Dune::TupleVector{1,2.0,3.0f,4u};
static_assert(std::is_same_v<decltype(tv1),Dune::TupleVector<int,double,float,unsigned int>>);
auto tv2 = Dune::TupleVector{std::tuple{1,2.0,3.0f,4u}};
static_assert(std::is_same_v<decltype(tv2),Dune::TupleVector<int,double,float,unsigned int>>);
auto tv3 = Dune::TupleVector{std::pair{1,2.0}};
static_assert(std::is_same_v<decltype(tv3),Dune::TupleVector<int,double>>);
// test construction with l-values
Dune::FieldVector<double,2> arg1{};
std::vector<float> arg2{};
auto tv4 = Dune::TupleVector{arg1,arg2};
static_assert(std::is_same_v<decltype(tv4),Dune::TupleVector<Dune::FieldVector<double,2>,std::vector<float>>>);
// test construction with allocators
auto tv5 = Dune::TupleVector{std::allocator_arg_t{}, std::allocator<float>{}, arg1, arg2};
static_assert(std::is_same_v<decltype(tv4),decltype(tv5)>);
auto tv6 = Dune::TupleVector{std::allocator_arg_t{}, std::allocator<float>{}, std::tuple{arg1, arg2}};
static_assert(std::is_same_v<decltype(tv4),decltype(tv6)>);
auto tv7 = Dune::TupleVector{std::allocator_arg_t{}, std::allocator<float>{}, std::pair{arg1, arg2}};
static_assert(std::is_same_v<decltype(tv4),decltype(tv7)>);
}
return test.exit();
}
......@@ -35,13 +35,6 @@ class TupleVector : public std::tuple<T...>
{
using Base = std::tuple<T...>;
template<class... TT>
using TupleConstructorDetector = decltype(Base(std::declval<TT&&>()...));
template<class... TT>
using hasTupleConstructor = Dune::Std::is_detected<TupleConstructorDetector, TT...>;
public:
/** \brief Construct from a set of arguments
......@@ -51,7 +44,7 @@ public:
* list.
*/
template<class... TT,
std::enable_if_t<hasTupleConstructor<TT...>::value, int> = 0>
class = std::void_t<decltype(Base(std::declval<TT&&>()...))>>
constexpr TupleVector(TT&&... tt) :
Base(std::forward<TT>(tt)...)
{}
......@@ -86,6 +79,29 @@ public:
}
};
/// \name Deduction guides for TupleVector
/// \relates TupleVector
/// @{
template<class... T>
TupleVector(T...) -> TupleVector<T...>;
template<class T1, class T2>
TupleVector(std::pair<T1, T2>) -> TupleVector<T1, T2>;
template<class... T>
TupleVector(std::tuple<T...>) -> TupleVector<T...>;
template <class Alloc, class... T>
TupleVector(std::allocator_arg_t, Alloc, T...) -> TupleVector<T...>;
template<class Alloc, class T1, class T2>
TupleVector(std::allocator_arg_t, Alloc, std::pair<T1, T2>) -> TupleVector<T1, T2>;
template<class Alloc, class... T>
TupleVector(std::allocator_arg_t, Alloc, std::tuple<T...>) -> TupleVector<T...>;
/// @}
template<class... T>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment