ftmplでfold

コンパイル通すのに1時間くらいかかった。
結局、type_tが邪魔なので外すメタ関数が必要になった。


あと、decltype( ( T ) )忘れがち。

#include <iostream>
#include <cxxabi.h>
#include "vector.hpp"
#include "type.hpp"
#include "unwrap.hpp"
#include "id.hpp"
#include "is_same.hpp"
#include "apply.hpp"
#include "fold.hpp"

char* demangle(const char *demangle) {
    int status;
    return abi::__cxa_demangle(demangle, 0, 0, &status);
}

using namespace boost::ftmpl;

template <class T>
struct untype {
    typedef T& type;
};

template <class T>
struct untype<type_t<T>&> {
    typedef T& type;
};

struct plus {
    template <class T, class U>
    auto operator()(T& t, U& u) const -> typename untype<decltype((t + u))>::type;
};

int main()
{
    typedef decltype(value<int, 6>()) expected;

    typedef decltype(vector(value<int, 1>(), value<int, 2>(), value<int, 3>())) v;
    typedef decltype(fold(type<plus>(), value<int, 0>(), id<v>()))              result;

    static_assert(unwrap_value<BOOST_FTMPL_UNWRAP(
        apply(is_same, id<result>(), id<expected>())
    )>::value, "failed");

    std::cout << demangle(typeid(result).name())   << std::endl;
    std::cout << demangle(typeid(expected).name()) << std::endl;
}
boost::ftmpl::value_t<int, 6>
boost::ftmpl::value_t<int, 6>

たぶん、現時点のfoldは実装がおかしい。
int_が使えないようなものになってるし、ファンクタ側の負担も大きいので、
fold内でのtype_tのwrap/unwrapは見直しが必要。