Created
January 19, 2019 20:48
-
-
Save marzer/9dcaccf73a599fd798d8159c2786993d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//godbolt: https://godbolt.org/z/6Ffp3J | |
#include <cstdint> | |
#include <utility> | |
using namespace std; | |
template <typename T, size_t N> | |
class Test | |
{ | |
private: | |
template <typename T_, size_t N_> | |
friend class Test; | |
T data[N]; | |
constexpr Test() noexcept = default; | |
public: | |
template <typename... U> | |
constexpr Test(U &&... vals) noexcept | |
: data{ std::forward<U>(vals)... } | |
{ | |
} | |
template <size_t N_> | |
constexpr auto operator+ (const Test<T, N_>& rhs) const noexcept | |
{ | |
auto output = Test<T, N+N_>{}; | |
for (size_t i = 0; i < N; i++) | |
output.data[i] = data[i]; | |
for (size_t i = 0; i < N_; i++) | |
output.data[N+i] = rhs.data[i]; | |
return output; | |
} | |
}; | |
inline constexpr auto foo = Test<int, 3>{1,2,3}; | |
inline constexpr auto bar = Test<int, 5>{4,5,6,7,8}; | |
inline constexpr auto kek = foo + bar; | |
int main() | |
{ | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment