flexiblesusy is hosted by Hepforge, IPPP Durham
FlexibleSUSY
concatenate.hpp
Go to the documentation of this file.
1// ====================================================================
2// This file is part of FlexibleSUSY.
3//
4// FlexibleSUSY is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published
6// by the Free Software Foundation, either version 3 of the License,
7// or (at your option) any later version.
8//
9// FlexibleSUSY is distributed in the hope that it will be useful, but
10// WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12// General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with FlexibleSUSY. If not, see
16// <http://www.gnu.org/licenses/>.
17// ====================================================================
18
19#ifndef H_FS_CONCATENATE
20#define H_FS_CONCATENATE
21
22#include <array>
23#include <type_traits>
24
25namespace flexiblesusy
26{
27namespace detail
28{
29template <class T>
30struct value_type {
31 using type = typename T::value_type;
32};
33
34template <class... Args>
36 using type =
37 typename std::common_type<typename value_type<Args>::type...>::type;
38};
39
40template <int... Args>
41struct sum;
42
43template <int V1, int... Tail>
44struct sum<V1, Tail...> {
45 static constexpr int value = V1 + sum<Tail...>::value;
46};
47
48template <>
49struct sum<> {
50 static constexpr int value = 0;
51};
52
53namespace result_of
54{
55template <class... Args>
57 using type = std::array<
60};
61} // namespace result_of
62
63template <class... Args>
65
66template <class T, class... Args>
67struct concatenate_impl<T, Args...> {
68 template <class OutputIterator>
69 void operator()(OutputIterator it, T&& t, Args&&... args)
70 {
71 auto next = std::copy(t.begin(), t.end(), it);
72 concatenate_impl<Args...>{}(next, std::forward<Args>(args)...);
73 }
74};
75
76template <>
78 template <class OutputIterator>
79 void operator()(OutputIterator it)
80 {
81 }
82};
83} // namespace detail
84
85template <class... Args>
86typename detail::result_of::concatenate<Args...>::type
87concatenate(Args&&... args)
88{
89 using result_type = typename detail::result_of::concatenate<Args...>::type;
90 result_type result;
91
92 detail::concatenate_impl<Args...>{}(result.begin(),
93 std::forward<Args>(args)...);
94
95 return result;
96}
97} // namespace flexiblesusy
98
99#endif
detail::result_of::concatenate< Args... >::type concatenate(Args &&... args)
Definition: concatenate.hpp:87
typename std::common_type< typename value_type< Args >::type... >::type type
Definition: concatenate.hpp:37
void operator()(OutputIterator it, T &&t, Args &&... args)
Definition: concatenate.hpp:69
std::array< typename common_value_type< typename std::decay< Args >::type... >::type, sum< std::tuple_size< typename std::decay< Args >::type >::value... >::value > type
Definition: concatenate.hpp:59
typename T::value_type type
Definition: concatenate.hpp:31