nontype — std::nontype

nontype — std::nontype (비타입 태그)

std::nontype(및 std::nontype_t)은 비타입(non-type) 템플릿 인자를 함수 객체로 전달할 수 있게 하는 태그 도구예요. C++26에서 도입됐어요. <utility> 헤더에 있어요.

출처: cppreference

본문

// <utility> 헤더, C++26
template< auto V >
struct nontype_t { explicit nontype_t() = default; };   // (1)

template< auto V >
constexpr std::nontype_t<V> nontype{};                  // (2)

사용 예

std::nontype<int_constant> 형태로 비타입 값을 함수 객체에 바인딩할 수 있어요.

#include <utility>

// 비타입 템플릿 인자로 값 전달
template<auto V>
void use() {
    constexpr int val = V;   // V 사용
}

// nontype 태그로 명시
use<std::nontype<42>>();  // (개념상) 값 42 전달

std::nontype/std::nontype_t함수 객체 인자(INVOKE) 시그니처와 결합해, 비타입 템플릿 값을 타입으로 감싸 전달할 때 쓰여요.

특징

  • nontype_t<V>는 태그 타입, nontype<V>는 그 인스턴스.
  • 값을 타입 시스템에 통합해 함수에 전달.

std::nontype은 비타입 템플릿 값을 함수 객체·스코프에 바인딩하는 C++26 신규 도구예요. 최신 컴파일러 지원이 필요해요.

더 알아보기 (Learn more)

cppreference