如何解决C ++ 11:参数包传递给模板化的内存分配器的构造函数
说我有一个class Allocator
,其方法将以某种方式分配空间,在该空间中构造所需的对象,然后对所构造的对象执行某些操作。对象的类是异构的:我们可以在一个构建中调用多个类。简而言之,我需要一个如何写???的想法。此示例代码中的部分:
class Foo {
Foo( int i,double d,string s );
};
class Bar {
Bar( int i );
};
class Allocator {
template<typename T> Allocate( ??? );
}
template<typename T> Allocator::Allocate( ??? ) {
void* pv = /* memory is found somehow,perhaps using sizeof( T ) */;
T* pobj = new( pv ) T( ??? );
/* something is done with the new object */
}
/* user of this class would write something like this??? */
allocator.Allocate<Foo>( 1,2.3,"four" );
allocator.Allocate<Bar>( 1 );
我看过initializer_list<>
和参数包,但没有看到如何将它们与模板方法结合在一起。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。