basic_format_arg

basic_format_arg (서식 인자 접근)

basic_format_arg는 서식 지정 문자열에 전달된 인자에 접근할 수 있게 해 주는 클래스 템플릿이에요. 이 객체는 주로 std::make_format_args로 생성되며, std::visit_format_arg 또는 visit 멤버 함수를 통해 저장된 인자를 방문할 수 있어요. 기본적으로 std::variant처럼 동작하면서 다양한 타입의 인자를 안전하게 보관해요.

출처: cppreference

본문

<format> 헤더에 정의되어 있어요.

Defined in header <format>
template < class Context > class basic_format_arg ; (since C++20)

서식 지정 인자에 대한 접근을 제공해요.

basic_format_arg 객체는 일반적으로 std::make_format_args에 의해 생성되고, std::visit_format_arg 또는 visit 멤버 함수(C++26부터)를 통해 접근돼요.

basic_format_arg 객체는 내부적으로 다음 타입들의 std::variant를 저장하는 것처럼 동작해요:

  • std::monostate (기본 생성된 경우에만)
  • bool
  • Context::char_type
  • int
  • unsigned int
  • long long int
  • unsigned long long int
  • float
  • double
  • long double
  • const Context::char_type *
  • std::basic_string_view<Context::char_type>
  • const void *
  • basic_format_arg::handle

멤버 클래스

handle (C++20) 사용자 정의 타입의 객체 서식을 허용하는 type-erased 래퍼 (public member class)

멤버 함수

(constructor) (C++20) std::basic_format_arg를 생성해요 (public member function)
operator bool (C++20) 현재 객체가 서식 인자를 보유하고 있는지 확인해요 (public member function)
visit (C++26) 저장된 서식 인자를 방문해요 (public member function)

비멤버 함수

visit_format_arg (C++20) (C++26에서 deprecated) 사용자 정의 포맷터를 위한 인자 방문 인터페이스 (function template)

std::basic_format_arg::basic_format_arg

basic_format_arg () noexcept ; (since C++20)

기본 생성자예요. 서식 인자를 보유하지 않는 basic_format_arg를 생성해요. 저장된 객체의 타입은 std::monostate예요.

서식 인자를 보유하는 basic_format_arg를 만들려면 std::make_format_args를 사용해야 해요.

std::basic_format_arg::operator bool

explicit operator bool () const noexcept ; (since C++20)

*this가 서식 인자를 보유하고 있는지 확인해요.

*this가 서식 인자를 보유하고 있으면(즉, 저장된 객체가 std::monostate 타입이 아니면) true를 반환하고, 그렇지 않으면 false를 반환해요.

std::basic_format_arg::visit

template < class Visitor > decltype ( auto ) visit ( this basic_format_arg arg , Visitor && vis ); (1) (since C++26)
template < class R , class Visitor > R visit ( this basic_format_arg arg , Visitor && vis ); (2) (since C++26)

방문자 visarg에 포함된 객체에 적용해요.

visit 함수는 호출된 basic_format_arg 객체를 수정하지 않아요. vis를 호출할 때 객체의 복사본이 사용되기 때문이에요.

참고 사항

Feature-test macro Value Std Feature
__cpp_lib_format 202306L (C++26) Member visit

예제

이 섹션은 불완전해요. 이유: 예제 없음

같이 보기

basic_format_args format_args wformat_args (C++20) (C++20) (C++20) 모든 서식 인자에 대한 접근을 제공하는 클래스 (class template)

더 알아보기 (Learn more)

cppreference