C ++模板元编程:编译时跟踪器/计数器

时间:2018-06-09 16:58:19

标签: c++ templates counter trace template-meta-programming

namespace tracers {
    template <size_t N, bool B>
    struct allocated_buffer_tracer {
        static constexpr size_t value = N; // value represents the amount of declared buffer objects with is_allocated = std::true_type
        using type = allocated_buffer_tracer<N+B, B>;
    };
}


template <typename is_allocated> // is_allocated is either std::true_type or std::false_type
struct Buffer {
    constexpr Buffer()
    {
        // something like tracers::allocated_buffer_tracer<N,is_allocated::value>;
    }
};

由于无法自己增加值,因此必须从类型派生值(取决于模板参数)。但是,我在尝试完成这项工作时遇到了问题(在编译时)。感谢阅读和可能的帮助。

0 个答案:

没有答案