是否可以在不指定或不知道这些参数的情况下转发声明使用默认参数的类?
例如,我想boost::ptr_list< TYPE >
在 Traits 类中声明 a 而无需将整个 Boost 库拖到包含该特征的每个文件中。我想声明
namespace boost { template<class T> class ptr_list< T >; }
,但这不起作用,因为它与真正的类声明不完全匹配:
template < class T,
class CloneAllocator = heap_clone_allocator,
class Allocator = std::allocator<void*>
>
class ptr_list { ... };
我的选择是只能忍受它还是boost::ptr_list< TYPE, boost::heap_clone_allocator, std::allocator<void*>
在我的特征类中指定?(如果我使用后者,我想我还必须转发 declareboost::heap_clone_allocator
和 include <memory>
。)
我浏览了 Stroustrup 的书 SO,以及互联网的其他内容,但没有找到解决方案。通常人们担心不包含 STL,解决方案是“只包含 STL 头”。但是,Boost 是一个更庞大且编译器密集型的库,因此除非绝对必须,否则我宁愿将其省略。