forked from boostorg/assert
Add a source_location constructor from std::source_location
This commit is contained in:
@@ -14,6 +14,7 @@ http://www.boost.org/LICENSE_1_0.txt
|
|||||||
|
|
||||||
* `source_location().file_name()` and `source_location().function_name()`
|
* `source_location().file_name()` and `source_location().function_name()`
|
||||||
now return `""` instead of `"(unknown)"`.
|
now return `""` instead of `"(unknown)"`.
|
||||||
|
* Added a `source_location` constructor from `std::source_location`.
|
||||||
|
|
||||||
## Changes in 1.78.0
|
## Changes in 1.78.0
|
||||||
|
|
||||||
|
@@ -29,8 +29,9 @@ namespace boost
|
|||||||
struct source_location
|
struct source_location
|
||||||
{
|
{
|
||||||
constexpr source_location() noexcept;
|
constexpr source_location() noexcept;
|
||||||
constexpr source_location(char const* file, uint_least32_t line,
|
constexpr source_location( char const* file, uint_least32_t line,
|
||||||
char const* function, uint_least32_t column = 0) noexcept;
|
char const* function, uint_least32_t column = 0 ) noexcept;
|
||||||
|
constexpr source_location( std::source_location const& loc ) noexcept;
|
||||||
|
|
||||||
constexpr char const* file_name() const noexcept;
|
constexpr char const* file_name() const noexcept;
|
||||||
constexpr char const* function_name() const noexcept;
|
constexpr char const* function_name() const noexcept;
|
||||||
@@ -60,14 +61,22 @@ Effects: :: Constructs a `source_location` object for which `file_name()`
|
|||||||
and `function_name()` return `""`, and `line()` and `column()` return `0`.
|
and `function_name()` return `""`, and `line()` and `column()` return `0`.
|
||||||
|
|
||||||
```
|
```
|
||||||
constexpr source_location(char const* file, uint_least32_t line,
|
constexpr source_location( char const* file, uint_least32_t line,
|
||||||
char const* function, uint_least32_t column = 0) noexcept;
|
char const* function, uint_least32_t column = 0 ) noexcept;
|
||||||
```
|
```
|
||||||
|
|
||||||
Effects: :: Constructs a `source_location` object for which `file_name()`
|
Effects: :: Constructs a `source_location` object for which `file_name()`
|
||||||
returns `file`, `function_name()` returns `function`, `line()` returns the
|
returns `file`, `function_name()` returns `function`, `line()` returns the
|
||||||
`line` argument and `column()` returns the `column` argument.
|
`line` argument and `column()` returns the `column` argument.
|
||||||
|
|
||||||
|
```
|
||||||
|
constexpr source_location( std::source_location const& loc ) noexcept;
|
||||||
|
```
|
||||||
|
|
||||||
|
Effects: :: Constructs a `source_location` object for which `file_name()`
|
||||||
|
returns `loc.file_name()`, `function_name()` returns `loc.function_name()`,
|
||||||
|
`line()` returns `loc.line()` argument and `column()` returns `loc.column()`.
|
||||||
|
|
||||||
## to_string
|
## to_string
|
||||||
|
|
||||||
```
|
```
|
||||||
|
@@ -14,6 +14,10 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
|
||||||
|
#if !defined(BOOST_NO_CXX20_HDR_SOURCE_LOCATION)
|
||||||
|
# include <source_location>
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace boost
|
namespace boost
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -36,6 +40,14 @@ public:
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !defined(BOOST_NO_CXX20_HDR_SOURCE_LOCATION)
|
||||||
|
|
||||||
|
BOOST_CONSTEXPR source_location( std::source_location const& loc ) BOOST_NOEXCEPT: file_( loc.file_name() ), function_( loc.function_name() ), line_( loc.line() ), column_( loc.column() )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
BOOST_CONSTEXPR char const * file_name() const BOOST_NOEXCEPT
|
BOOST_CONSTEXPR char const * file_name() const BOOST_NOEXCEPT
|
||||||
{
|
{
|
||||||
return file_;
|
return file_;
|
||||||
|
@@ -25,5 +25,19 @@ int main()
|
|||||||
BOOST_TEST_EQ( loc.column(), 0 );
|
BOOST_TEST_EQ( loc.column(), 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !defined(BOOST_NO_CXX20_HDR_SOURCE_LOCATION)
|
||||||
|
|
||||||
|
{
|
||||||
|
std::source_location loc = std::source_location::current();
|
||||||
|
boost::source_location loc2 = loc;
|
||||||
|
|
||||||
|
BOOST_TEST_CSTR_EQ( loc2.file_name(), loc.file_name() );
|
||||||
|
BOOST_TEST_CSTR_EQ( loc2.function_name(), loc.function_name() );
|
||||||
|
BOOST_TEST_EQ( loc2.line(), loc.line() );
|
||||||
|
BOOST_TEST_EQ( loc2.column(), loc.column() );
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
return boost::report_errors();
|
return boost::report_errors();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user