2013-10-15 6 views

답변

2

당신이

static_assert(std::is_same<typename T::value_type,SomeType>::value, "type in the container is different"); 
+1

거의 맞습니다. 조금 누락되었습니다. – juanchopanza

+0

@juanchopanza 편집 됨, 감사합니다. –

1

를 사용할 수 ... 나는 static_assert(std::is_same<T::type,SomeType>)의 라인을 따라 뭔가를 생각하고 있지만, 물론 그 작동하지 않습니다

template <typename Container> 
MyFun(const Constainer& container) 
{ 
    static_assert(std::is_same<typename Container::value_type, SomeType>::value) 
    // I want to static_assert that all elements in Container are equal to SomeType 
} 
1

당신은,275 정의 된 컨테이너 유형을 Assumng

static_assert(std::is_same<typename T::value_type, SomeType>::value, 
       "It does not work"); 

같은 뭔가가 필요(표준 라이브러리 컨테이너처럼) 보유하는 요소의 유형이됩니다.

std::is_samestatic_assert을 참조하십시오.

관련 문제