[support.srcloc.class] (original) (raw)

17 Language support library [support]

17.8 Source location [support.srcloc]

17.8.2 Class source_location [support.srcloc.class]

17.8.2.1 General [support.srcloc.class.general]

namespace std { struct source_location { static consteval source_location current() noexcept;constexpr source_location() noexcept;constexpr uint_least32_t line() const noexcept;constexpr uint_least32_t column() const noexcept;constexpr const char* file_name() const noexcept;constexpr const char* function_name() const noexcept;private: uint_least32_t line_; uint_least32_t column_; const char* file_name_; const char* function_name_; };}

All of the following conditions are true:

[Note 1:

The intent of source_location is to have a small size and efficient copying.

It is unspecified whether the copy/move constructors and the copy/move assignment operators are trivial and/or constexpr.

— _end note_]

The data members file_name_ and function_name_always each refer to an ntbs.

The copy/move constructors and the copy/move assignment operators ofsource_location meet the following postconditions: Given two objects lhs and rhs of type source_location, where lhs is a copy/move result of rhs, and where rhs_p is a value denoting the state of rhsbefore the corresponding copy/move operation, then each of the following conditions is true:

17.8.2.2 Creation [support.srcloc.cons]

static consteval source_location current() noexcept;

Returns:

Remarks: Any call to current that appears as a default member initializer ([class.mem.general]), or as a subexpression thereof, should correspond to the location of the constructor definition or aggregate initialization that uses the default member initializer.

Any call to current that appears as a default argument ([dcl.fct.default]), or as a subexpression thereof, should correspond to the location of the invocation of the function that uses the default argument ([expr.call]).

[Example 1: struct s { source_location member = source_location::current();int other_member; s(source_location loc = source_location::current()) : member(loc) {} s(int blather) : other_member(blather) {} s(double) {} };void f(source_location a = source_location::current()) { source_location b = source_location::current(); } void g() { f(); source_location c = source_location::current(); f(c); } — _end example_]

constexpr source_location() noexcept;

Effects: The data members are initialized with valid but unspecified values.

17.8.2.3 Observers [support.srcloc.obs]

constexpr uint_least32_t line() const noexcept;

constexpr uint_least32_t column() const noexcept;

constexpr const char* file_name() const noexcept;

constexpr const char* function_name() const noexcept;