Mercurial > lbo > hg > ctmp
changeset 13:a5357921e566
higherorder
author | Lewin Bormann <lbo@spheniscida.de> |
---|---|
date | Thu, 26 Mar 2020 10:53:17 +0100 |
parents | 1ebc743c3d85 |
children | ab9ed41eb455 |
files | CMakeLists.txt src/higherorder.cc src/units.cc |
diffstat | 3 files changed, 31 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/CMakeLists.txt Thu Mar 26 10:06:28 2020 +0100 +++ b/CMakeLists.txt Thu Mar 26 10:53:17 2020 +0100 @@ -7,6 +7,7 @@ add_executable(describe_type src/describe_type.cc) add_executable(example src/example.cc) add_executable(fac src/fac.cc) +add_executable(higherorder src/higherorder.cc) add_executable(replace_type src/replace_type.cc) add_executable(sequence src/sequence.cc) add_executable(units src/units.cc)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/higherorder.cc Thu Mar 26 10:53:17 2020 +0100 @@ -0,0 +1,29 @@ +#include <iostream> +#include <boost/mpl/apply.hpp> +#include <boost/mpl/int.hpp> +#include <boost/mpl/lambda.hpp> +#include <boost/mpl/placeholders.hpp> +#include <boost/mpl/plus.hpp> + +namespace mpl = boost::mpl; + +struct plus10 { + template<typename X> + struct apply { + typedef typename mpl::int_<10 + X::value>::type type; + }; +}; + +template<typename F, typename X> +struct apply_twice { + typedef typename F::template apply<X>::type once; + typedef typename F::template apply<once>::type type; +}; + +int main(void) { + typedef mpl::int_<3> three; + typedef mpl::lambda<mpl::plus<mpl::int_<11>, mpl::_1>>::type plus11; + + std::cout << apply_twice<plus11, three>::type::value << std::endl; + return 0; +}
--- a/src/units.cc Thu Mar 26 10:06:28 2020 +0100 +++ b/src/units.cc Thu Mar 26 10:53:17 2020 +0100 @@ -80,7 +80,7 @@ template <typename U1, typename U2> struct multiply_units { - typedef typename mpl::transform<U1, U2, make_lambda<plus>>::type type; + typedef typename mpl::transform<U1, U2, plus<mpl::_1, mpl::_2>>::type type; }; template <typename U1, typename U2>