format_enable_nonlocking_formatter_optimization

format_enable_nonlocking_formatter_optimization (비잠금 포맷터 최적화 활성화)

이 페이지는 C++23부터 사용 가능한 std::enable_nonlocking_formatter_optimization 템플릿에 대해 설명해요. 이 템플릿은 구현체가 std::printstd::println의 효율적인 구현을 활성화하는 데 사용되는 constexpr bool 변수 템플릿이에요. 특정 타입에 대해 이 값이 true로 설정되면 해당 타입의 인자를 더 효율적인 방식으로 출력할 수 있어요.

출처: cppreference

본문

개요

<format> 헤더에 다음과 같이 정의되어 있어요:

Defined in header
template < class T > constexpr bool enable_nonlocking_formatter_optimization = false ; (since C++23)

이 템플릿은 구현체가 std::printstd::println의 효율적인 구현을 활성화하는 데 사용될 수 있어요.

std::enable_nonlocking_formatter_optimization<T>가 true라면, T 타입의 인자를 더 효율적인 방식으로 출력할 수 있어요 (자세한 내용은 std::print를 참고하세요). std::enable_nonlocking_formatter_optimization 특수화는 다음 경우에 true가 될 수 있어요:

  • T가 std::formatter<T, CharT>가 기본 표준 특수화 또는 라이브러리 타입에 대한 표준 특수화인 타입 중 하나인 경우 (아래 참고).
  • 프로그램이 cv 한정자가 없는 프로그램 정의 타입 T에 대해 이 템플릿을 특수화할 수 있어요. 이러한 특수화는 상수 표현식에서 사용 가능해야 하며 const bool 타입이어야 해요.

기본 표준 특수화

다음 목록에서 CharTchar 또는 wchar_t이고, ArithmeticTchar, wchar_t, char8_t, char16_t, char32_t를 제외한 cv 한정자가 없는 모든 산술 타입이에요:

문자 포맷터에 대한 비잠금 플래그
template <> constexpr bool enable_nonlocking_formatter_optimization < CharT > = true ; (1)
문자열 포맷터에 대한 비잠금 플래그
template <> constexpr bool enable_nonlocking_formatter_optimization < CharT *> = true ; (2)
template <> constexpr bool enable_nonlocking_formatter_optimization < const CharT *> = true ; (3)
template < std :: size_t N > constexpr bool enable_nonlocking_formatter_optimization < CharT [ N ] > = true ; (4)
template < class Traits , class Alloc > constexpr bool enable_nonlocking_formatter_optimization < std :: basic_string < CharT , Traits , Alloc >> = true ; (5)
template < class Traits > constexpr bool enable_nonlocking_formatter_optimization < std :: basic_string_view < CharT , Traits >> = true ; (6)
산술 포맷터에 대한 비잠금 플래그
template <> constexpr bool enable_nonlocking_formatter_optimization < ArithmeticT > = true ; (7)
포인터 포맷터에 대한 비잠금 플래그
template <> constexpr bool enable_nonlocking_formatter_optimization < std :: nullptr_t > = true ; (8)
template <> constexpr bool enable_nonlocking_formatter_optimization < void *> = true ; (9)
template <> constexpr bool enable_nonlocking_formatter_optimization < const void *> = true ; (10)

라이브러리 타입에 대한 표준 특수화

다음 표준 템플릿의 모든 특수화에 대한 enable_nonlocking_formatter_optimization 특수화는 true로 정의돼요:

  • 템플릿 매개변수 타입 TimeZonePtrconst std::chrono::time_zone*std::chrono::zoned_time

다음 표준 템플릿의 모든 특수화에 대한 enable_nonlocking_formatter_optimization 특수화는 조건부로 true로 정의돼요:

  • std::pair
  • std::tuple
  • std::chrono::duration

범위 형식 종류가 std::range_format::disabled가 아닌 모든 포맷 가능한 범위 타입에 대한 enable_nonlocking_formatter_optimization 특수화는 항상 false로 정의돼요.

참고 사항

Feature-test macro Value Std Feature
__cpp_lib_print 202403L (C++26) (DR23) 스트림 잠금을 사용한 형식화된 출력
202406L (C++26) (DR23) 더 많은 포맷 가능한 타입에 대한 비잠금 포맷터 최적화 활성화

같이 보기

formatter (C++20) 주어진 타입에 대한 형식화 규칙을 정의해요 (클래스 템플릿)
print (C++23) 인자의 형식화된 표현을 사용하여 stdout 또는 파일 스트림에 출력해요 (함수 템플릿)
println (C++23) 각 출력이 추가 줄바꿈으로 종료된다는 점을 제외하면 std::print와 동일해요 (함수 템플릿)

더 알아보기 (Learn more)

cppreference