• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1////
2Copyright 2019 Peter Dimov
3Distributed under the Boost Software License, Version 1.0.
4http://www.boost.org/LICENSE_1_0.txt
5////
6
7[#source_location_support]
8# Source Location Support, <boost/assert/source_location.hpp>
9:toc:
10:toc-title:
11:idprefix:
12
13## Description
14
15The header `<boost/assert/source_location.hpp>` defines `source_location`,
16a class representing a source location and containing file, line, function
17and column information. It's similar to `std::source_location` from {cpp}20,
18but only requires {cpp}03.
19
20The macro `BOOST_CURRENT_LOCATION` creates a `source_location` object
21containing information about the current source location.
22
23## Synopsis
24
25```
26namespace boost
27{
28
29struct source_location
30{
31  constexpr source_location() noexcept;
32  constexpr source_location(char const* file, uint_least32_t line,
33    char const* function, uint_least32_t column = 0) noexcept;
34
35  constexpr char const* file_name() const noexcept;
36  constexpr char const* function_name() const noexcept;
37  constexpr uint_least32_t line() const noexcept;
38  constexpr uint_least32_t column() const noexcept;
39};
40
41template<class E, class T>
42  std::basic_ostream<E, T> &
43  operator<<( std::basic_ostream<E, T> & os, source_location const & loc );
44
45} // namespace boost
46
47#define BOOST_CURRENT_LOCATION \
48  ::boost::source_location(__FILE__, __LINE__, BOOST_CURRENT_FUNCTION)
49```
50
51## source_location
52
53```
54constexpr source_location() noexcept;
55```
56
57Effects: :: Constructs a `source_location` object for which `file_name()`
58and `function_name()` return `"(unknown)"`, and `line()` and `column()`
59return `0`.
60
61```
62constexpr source_location(char const* file, uint_least32_t line,
63  char const* function, uint_least32_t column = 0) noexcept;
64```
65
66Effects: :: Constructs a `source_location` object for which `file_name()`
67returns `file`, `function_name()` returns `function`, `line()` returns the
68`line` argument and `column()` returns the `column` argument.
69
70## operator<<
71
72```
73template<class E, class T>
74  std::basic_ostream<E, T> &
75  operator<<( std::basic_ostream<E, T> & os, source_location const & loc );
76```
77
78Effects: :: Outputs a string representation of `loc` to `os`.
79Returns: :: `os`.
80
81## BOOST_CURRENT_LOCATION
82
83When `BOOST_DISABLE_CURRENT_LOCATION` is not defined, the definition of
84`BOOST_CURRENT_LOCATION` is:
85
86```
87#define BOOST_CURRENT_LOCATION \
88  ::boost::source_location(__FILE__, __LINE__, BOOST_CURRENT_FUNCTION)
89```
90
91Otherwise, `BOOST_CURRENT_LOCATION` is defined as:
92
93```
94#define BOOST_CURRENT_LOCATION ::boost::source_location()
95```
96
97This allows producing executables that contain no identifying information,
98for security reasons.
99