2016-06-11 4 views
2

C++ 표준은 템플릿 선언에 속성을 설정할 수 있습니까? 예를 들어 :속성을 템플릿에 적용 할 수 있습니까?

[[attr1]] template <typename T [[attr2]] > [[attr3]] 
class [[attr4]] C {}; 

나는 attr4 템플릿 인스턴스 (즉, 예를 들어, T<int>T<char>에 속성 것)에 대한 유효한 속성으로 간주됩니다 믿습니다.

컴파일러는 attr1 또는 attr3을 유효하게 간주합니까? (무시 되더라도)?

attr2도 유효할까요? 나는 생각하지 않는다. 그러나 나는 확실하지 않다. 이 문제는 인스턴스화에 사용 된 주어진 유형에 속성을 "추가"하지만 IIRC의 현재 템플릿 매개 변수에 모든 속성이 무시되는 경우 문제가 발생합니다.

attr1 및/또는 attr3 나의 관심은 템플릿에 지정된 속성이 자동으로 유형의 주어진 집합 클래스의 인스턴스를 강제 사용자 정의 테스트 DSL,입니다.

답변

3

나는 C++ 문법에 팠 여기에 관련 부분입니다 :

당신이 나를 믿는다면 declarationattribute-specifier-seq로 시작하지 않을 수, [[attr1]][[attr3]]을 금지
declaration: 
    block-declaration 
    template-declaration 

template-declaration: 
    template < template-parameter-list > declaration 

. 정규식에서 [[attr2]]을 금지


template-parameter-list: 
    template-parameter 

template-parameter: 
    type-parameter 

type-parameter: 
    type-parameter-key ..._opt identifier_opt 

type-parameter-key: 
    class 
    typename 

, identifieruniversal-character-name다른 구현 정의 문자로, [a-zA-Z_][a-zA-Z_0-9]*입니다. [[attr4]]

수 있습니다


declaration: 
    block-declaration 

simple-declaration: 
    decl-specifier-seq_opt init-declarator-list_opt ; 

decl-specifier-seq: 
    decl-specifier attribute-specifier-seq_opt 

decl-specifier: 
    type-specifier 

type-specifier: 
    class-specifier 

class-specifier: 
    class-head { member-specification_opt } 

class-head: 
    class-key attribute-specifier-seq_opt class-head-name class-virt-specifier_opt base-clause_opt 

관련 문제