C++元编程技术——ebo的使用实例
在C++编程中,突破内存限制是必不可少的。EBO(Empty Base Optimization)是一种有效的技术,它可以在避免额外的内存消耗下实现多重继承。
Boost.Hana提供一个非常好的ebo窃听器来帮助我们使用ebo。我们将通过以下测试程序来演示它的用法:
#include <iostream>
#include <type_traits>
#include <boost/hana.hpp>
using boost::hana::detail::ebo;
template<typename Head, typename Tail>
struct Node : ebo<Head>, Tail
{
using ebo<Head>::ebo;
};
template<typename... Ts>
using List = typename boost::hana::fold_left<
boost::hana::tuple<Ts...>,
boost::hana::type<boost::hana::tuple<>>,
boost::hana::template_<Node>
>::type::base;
templa