Skip to content

Instantly share code, notes, and snippets.

@benloong
Created December 6, 2016 01:54
Show Gist options
  • Save benloong/edda39904496c49b1bbe0d8d135f435e to your computer and use it in GitHub Desktop.
Save benloong/edda39904496c49b1bbe0d8d135f435e to your computer and use it in GitHub Desktop.
template<typename L1, typename L2>
struct S : L1, L2
{
S(L1 l1, L2 l2) :L1( std::move(l1) ), L2( std::move(l2) )
{
}
using L1::operator();
using L2::operator();
};
template<typename L1, typename L2>
auto make_combined(L1&& l1, L2 && l2) {
return S<std::decay_t<L1>, std::decay_t<L2>>(std::forward<L1>(l1), std::forward<L2>(l2));
}
int main()
{
auto l1 = []() {return 10; };
auto l2 = [](int x) {return x*x; };
// auto combined = S(l1, l2); // this compile in gcc7 using c++17 class template deduction
auto combined = S<decltype(l1), decltype(l2)>(l1, l2);
auto combined2 = make_combined(l1, l2);
return combined(10) + combined() + combined2(20) + combined2();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment