123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- #include <iostream>
- template <class C>
- struct Scalar
- {
- C c;
- constexpr C & operator*() { return this->c; }
- constexpr C const & operator*() const { return this->c; }
- };
- template <class C> constexpr auto scalar(C && c) { return Scalar<C> { std::forward<C>(c) }; }
- template <class T> requires (std::is_scalar_v<std::decay_t<T>>)
- constexpr decltype(auto)
- start(T && t) { return scalar(std::forward<T>(t)); }
- template <class T>
- constexpr decltype(auto)
- start(Scalar<T> && t) { return std::forward<decltype(t)>(t); }
- template <class A>
- constexpr decltype(auto)
- FLAT(A && a)
- {
- return *(start(std::forward<A>(a)));
- }
- template <class A, class B>
- constexpr auto operator +(A && a, B && b)
- {
- return FLAT(std::forward<A>(a)) + FLAT(std::forward<B>(b));
- }
- int main()
- {
-
-
- constexpr int q = 1;
- constexpr int x1 = q + scalar(2);
- std::cout << x1 << std::endl;
-
-
- }
|