From 8c11c71e5690f7803e0f9fdd5bcdc3abb36e74b2 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Mon, 25 Nov 2019 03:57:06 +0200 Subject: [PATCH] Document source_location --- doc/index-docinfo-footer.html | 1 + doc/index.adoc | 4 +- doc/source_location.adoc | 82 +++++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 doc/source_location.adoc diff --git a/doc/index-docinfo-footer.html b/doc/index-docinfo-footer.html index b27346f..51969f4 100644 --- a/doc/index-docinfo-footer.html +++ b/doc/index-docinfo-footer.html @@ -1,5 +1,6 @@  diff --git a/doc/index.adoc b/doc/index.adoc index 6e5026e..883e664 100644 --- a/doc/index.adoc +++ b/doc/index.adoc @@ -19,8 +19,8 @@ similar in behavior and purpose to the standard macro `assert` from ``. :leveloffset: +1 include::assert.adoc[] - include::current_function.adoc[] +include::source_location.adoc[] :leveloffset: -1 @@ -29,7 +29,7 @@ include::current_function.adoc[] This documentation is -* Copyright 2002, 2007, 2014, 2017 Peter Dimov +* Copyright 2002, 2007, 2014, 2017, 2019 Peter Dimov * Copyright 2011 Beman Dawes * Copyright 2015 Ion Gaztañaga * Distributed under the http://www.boost.org/LICENSE_1_0.txt[Boost Software License, Version 1.0]. diff --git a/doc/source_location.adoc b/doc/source_location.adoc new file mode 100644 index 0000000..905ee1f --- /dev/null +++ b/doc/source_location.adoc @@ -0,0 +1,82 @@ +//// +Copyright 2019 Peter Dimov +Distributed under the Boost Software License, Version 1.0. +http://www.boost.org/LICENSE_1_0.txt +//// + +# Source Location Support, +:toc: +:toc-title: +:idprefix: + +## Description + +The header `` defines `source_location`, +a class representing a source location and containing file, line, function +and column information. It's similar to `std::source_location` from {cpp}20, +but only requires {cpp}03. + +The macro `BOOST_CURRENT_LOCATION` creates a `source_location` object +containing information about the current source location. + +## Synopsis + +``` +namespace boost +{ + +struct source_location +{ + constexpr source_location() noexcept; + constexpr source_location(char const* file, uint_least32_t line, + char const* function, uint_least32_t column = 0) noexcept; + + constexpr char const* file_name() const noexcept; + constexpr char const* function_name() const noexcept; + constexpr uint_least32_t line() const noexcept; + constexpr uint_least32_t column() const noexcept; +}; + +} // namespace boost + +#define BOOST_CURRENT_LOCATION \ + ::boost::source_location(__FILE__, __LINE__, BOOST_CURRENT_FUNCTION) +``` + +## source_location + +``` +constexpr source_location() noexcept; +``` + +Effects: :: Constructs a `source_location` object for which `file_name()` +and `function_name()` return `"(unknown)"`, and `line()` and `column()` +return `0`. + +``` +constexpr source_location(char const* file, uint_least32_t line, + char const* function, uint_least32_t column = 0) noexcept; +``` + +Effects: :: Constructs a `source_location` object for which `file_name()` +returns `file`, `function_name()` returns `function`, `line()` returns the +`line` argument and `column()` returns the `column` argument. + +## BOOST_CURRENT_LOCATION + +When `BOOST_DISABLE_CURRENT_LOCATION` is not defined, the definition of +`BOOST_CURRENT_LOCATION` is: + +``` +#define BOOST_CURRENT_LOCATION \ + ::boost::source_location(__FILE__, __LINE__, BOOST_CURRENT_FUNCTION) +``` + +Otherwise, `BOOST_CURRENT_LOCATION` is defined as: + +``` +#define BOOST_CURRENT_LOCATION ::boost::source_location() +``` + +This allows producing executables that contain no identifying information, +for security reasons.