C++ Logo

std-discussion

Advanced search

Fwd: about reusing source_location type

From: Jordi Vilar <development_at_[hidden]>
Date: Wed, 4 Aug 2021 16:27:50 +0200
Hi evreyone,

I would like to ask you about your oppinion on the closed design for
source_location type.

As currently designed, a source_location can be constructed by either
the static source_location::current() function or a default
constructor.

The source_location::current() static function fills the
line/column/file/func fields by using compiler magic as a consteval.
That's great, and that's the intended usage.

The default constructor in the other hand is of little value as there
is no way to initialize the internal fields in any way.

This makes the reuse of this type impossible. For instance, the
stacktrace_entry could be defined by means of reusing this type to
convey the source location information. I don't know if it was
considered during the review of the stacktrace facility, in the
p0881r7 I only see a reference to aligning behavior with
source_location regarding the source_file.

Is there any deep reason for not having a constructor allowing
initializing all four fields?

Best regards,

Jordi

Received on 2021-08-04 09:28:04