template <unsigned int N>

详见:http://stackoverflow.com/questions/499106/what-does-template-unsigned-int-n-mean

 

You can have several kinds of template parameters

 

Type Parameters.

Types

Templates (only classes, no functions)

Non-type Parameters

Pointers

References

Integral constant expressions

What you have there is of the last kind. It's a compile time constant (so-called constant expression) and is of type integer or enumeration. After looking it up in the standard, i had to move class templates up into the types section - even though templates are not types. But they are called type-parameters for the purpose of describing those kinds nonetheless. You can have pointers (and also member pointers) and references to objects/functions that have external linkage (those that can be linked to from other object files and whose address is unique in the entire program). Examples:

 

Template type parameter:

 

template<typename T>

struct Container {

    T t;

};

 

// pass type "long" as argument.

Container<long> test;

Template integer parameter:

 

template<unsigned int S>

struct Vector {

    unsigned char bytes[S];

};

 

// pass 3 as argument.

Vector<3> test;

Template pointer parameter (passing a pointer to a function)

 

template<void (*F)()>

struct FunctionWrapper {

    static void call_it() { F(); }

};

 

// pass address of function do_it as argument.

void do_it() { }

FunctionWrapper<&do_it> test;

Template reference parameter (passing an integer)

 

template<int &A>

struct SillyExample {

    static void do_it() { A = 10; }

};

 

// pass flag as argument

int flag;

SillyExample<flag> test;

Template template parameter.

 

template<template<typename T> class AllocatePolicy>

struct Pool {

    void allocate(size_t n) {

        int *p = AllocatePolicy<int>::allocate(n);

    }

};

 

// pass the template "allocator" as argument. 

template<typename T>

struct allocator { static T * allocate(size_t n) { return 0; } };

Pool<allocator> test;

A template without any parameters is not possible. But a template without any explicit argument is possible - it has default arguments:

 

template<unsigned int SIZE = 3>

struct Vector {

    unsigned char buffer[SIZE];

};

 

Vector<> test;

Syntactically, template<> is reserved to mark an explicit template specialization, instead of a template without parameters:

 

template<>

struct Vector<3> {

    // alternative definition for SIZE == 3

};

In file included from /home/yhdr/2-test-2023-06_v3/sent.h:24:0, from /home/yhdr/2-test-2023-06_v3/sent.cpp:1: /usr/include/c++/7/thread: In instantiation of ‘struct std::thread::_Invoker<std::tuple<void (*)(double*, double&, double&, double&, double&, double&), double**, std::reference_wrapper<double>, std::reference_wrapper<double>, std::reference_wrapper<double>, std::reference_wrapper<double>, std::reference_wrapper<double> > >’: /usr/include/c++/7/thread:127:22: required from ‘std::thread::thread(_Callable&&, _Args&& ...) [with _Callable = void (&)(double*, double&, double&, double&, double&, double&); _Args = {double**, std::reference_wrapper<double>, std::reference_wrapper<double>, std::reference_wrapper<double>, std::reference_wrapper<double>, std::reference_wrapper<double>}]’ /home/yhdr/2-test-2023-06_v3/sent.cpp:18:153: required from here /usr/include/c++/7/thread:240:2: error: no matching function for call to ‘std::thread::_Invoker<std::tuple<void (*)(double*, double&, double&, double&, double&, double&), double**, std::reference_wrapper<double>, std::reference_wrapper<double>, std::reference_wrapper<double>, std::reference_wrapper<double>, std::reference_wrapper<double> > >::_M_invoke(std::thread::_Invoker<std::tuple<void (*)(double*, double&, double&, double&, double&, double&), double**, std::reference_wrapper<double>, std::reference_wrapper<double>, std::reference_wrapper<double>, std::reference_wrapper<double>, std::reference_wrapper<double> > >::_Indices)’ operator()() ^~~~~~~~ /usr/include/c++/7/thread:231:4: note: candidate: template<long unsigned int ..._Ind> decltype (std::__invoke((_S_declval<_Ind>)()...)) std::thread::_Invoker<_Tuple>::_M_invoke(std::_Index_tuple<_Ind ...>) [with long unsigned int ..._Ind = {_Ind ...}; _Tuple = std::tuple<void (*)(double*, double&, double&, double&, double&, double&), double**, std::reference_wrapper<double>, std::reference_wrapper<double>, std::reference_wrapper<double>, std::reference_wrapper<double>, std::reference_wrapper<double> >] _M_invoke(_Index_tuple<_Ind...>)
最新发布
06-07
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值