Skip to content

Instantly share code, notes, and snippets.

@marzer
Created January 19, 2019 20:48
Show Gist options
  • Save marzer/9dcaccf73a599fd798d8159c2786993d to your computer and use it in GitHub Desktop.
Save marzer/9dcaccf73a599fd798d8159c2786993d to your computer and use it in GitHub Desktop.
//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