template <typename T>
MyFun(const T container)
{
// I want to static_assert that all elements in T are equal to SomeType
}
어떻게하면됩니까? ... 그것이 표준 컨테이너의 경우컨테이너의 기본 요소를 static_assert하려면 어떻게해야합니까?
이template <typename T>
MyFun(const T container)
{
// I want to static_assert that all elements in T are equal to SomeType
}
어떻게하면됩니까? ... 그것이 표준 컨테이너의 경우컨테이너의 기본 요소를 static_assert하려면 어떻게해야합니까?
이당신이
static_assert(std::is_same<typename T::value_type,SomeType>::value, "type in the container is different");
거의 맞습니다. 조금 누락되었습니다. – juanchopanza
@juanchopanza 편집 됨, 감사합니다. –
를 사용할 수 ... 나는 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
}
당신은,275 정의 된 컨테이너 유형을 Assumng
static_assert(std::is_same<typename T::value_type, SomeType>::value,
"It does not work");
같은 뭔가가 필요(표준 라이브러리 컨테이너처럼) 보유하는 요소의 유형이됩니다.
std::is_same
및 static_assert
을 참조하십시오.
어떻게 "작동하지 않습니까?" 어떤 오류가 발생합니까? – juanchopanza