format_formattable

format_formattable (포맷 가능 개념)

여기서는 C++23에서 도입된 formattable 개념(concept)에 대해 설명해요. 이 개념은 주어진 타입 TCharT 문자 타입을 사용하는 포맷 라이브러리에서 포맷될 수 있는지 검사해요. std::formatterBasicFormatterFormatter 요구 사항을 충족하는지 확인하는 역할을 해요.

출처: cppreference

본문

정의

<format> 헤더에 정의된 formattable 개념은 다음과 같아요.

template < class T , class CharT >
concept formattable = /* formattable_with */ < std :: remove_reference_t < T > , std :: basic_format_context < /* fmt_iter_for */ < CharT > , CharT > > ;

이 개념은 std::formatter<std::remove_cvref_t<T>, CharT>BasicFormatterFormatter 요구 사항을 충족하는지 지정해요. 만약 std::remove_reference_t<T>가 const 한정(const-qualified)이라면 Formatter 요구 사항도 함께 확인해요.

헬퍼 템플릿

노출 전용(exposition-only) 별칭 템플릿 /* fmt_iter_for */std::output_iterator<const CharT&>를 만족하는 지정되지 않은 타입을 산출해요.

template < class CharT >
using /* fmt_iter_for */ = /* unspecified */ ;

formattable_with 개념

노출 전용 개념 /* formattable_with */는 실제 검사를 수행해요.

template < class T , class Context , class Formatter = typename Context :: template formatter_type < std :: remove_const_t < T >> >
concept /* formattable_with */ =
    std :: semiregular < Formatter > &&
    requires ( Formatter & f , const Formatter & cf , T && t , Context fc , std :: basic_format_parse_context < typename Context :: char_type > pc ) {
        { f . parse ( pc ) } -> std :: same_as < typename decltype ( pc ) :: iterator > ;
        { cf . format ( t , fc ) } -> std :: same_as < typename Context :: iterator > ;
    };

결함 보고서

다음과 같은 동작 변경 결함 보고서가 이전에 발표된 C++ 표준에 소급 적용되었어요.

DR 적용 대상 발표된 동작 올바른 동작
LWG 3925 C++23 std::basic_format_context의 두 번째 템플릿 인자가 제공되지 않았음 제공됨

같이 보기

formatter (C++20) 주어진 타입에 대한 포맷 규칙을 정의해요 (클래스 템플릿)
BasicFormatter (C++20) 주어진 포맷 인자 타입과 문자 타입에 대한 포맷 연산을 추상화해요 (명명된 요구 사항)
Formatter (C++20) 포맷 라이브러리에서 사용되는 함수를 정의해요 (명명된 요구 사항)

더 알아보기 (Learn more)

cppreference