source_location 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // <experimental/source_location> -*- C++ -*-
  2. // Copyright (C) 2015-2018 Free Software Foundation, Inc.
  3. //
  4. // This file is part of the GNU ISO C++ Library. This library is free
  5. // software; you can redistribute it and/or modify it under the
  6. // terms of the GNU General Public License as published by the
  7. // Free Software Foundation; either version 3, or (at your option)
  8. // any later version.
  9. // This library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. // Under Section 7 of GPL version 3, you are granted additional
  14. // permissions described in the GCC Runtime Library Exception, version
  15. // 3.1, as published by the Free Software Foundation.
  16. // You should have received a copy of the GNU General Public License and
  17. // a copy of the GCC Runtime Library Exception along with this program;
  18. // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  19. // <http://www.gnu.org/licenses/>.
  20. /** @file experimental/source_location
  21. * This is a TS C++ Library header.
  22. */
  23. #ifndef _GLIBCXX_EXPERIMENTAL_SRCLOC
  24. #define _GLIBCXX_EXPERIMENTAL_SRCLOC 1
  25. #include <cstdint>
  26. namespace std {
  27. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  28. namespace experimental {
  29. inline namespace fundamentals_v2 {
  30. #define __cpp_lib_experimental_source_location 201505
  31. struct source_location
  32. {
  33. #ifndef _GLIBCXX_USE_C99_STDINT_TR1
  34. private:
  35. using uint_least32_t = unsigned;
  36. public:
  37. #endif
  38. // 14.1.2, source_location creation
  39. static constexpr source_location
  40. current(const char* __file = __builtin_FILE(),
  41. const char* __func = __builtin_FUNCTION(),
  42. int __line = __builtin_LINE(),
  43. int __col = 0) noexcept
  44. {
  45. source_location __loc;
  46. __loc._M_file = __file;
  47. __loc._M_func = __func;
  48. __loc._M_line = __line;
  49. __loc._M_col = __col;
  50. return __loc;
  51. }
  52. constexpr source_location() noexcept
  53. : _M_file("unknown"), _M_func(_M_file), _M_line(0), _M_col(0)
  54. { }
  55. // 14.1.3, source_location field access
  56. constexpr uint_least32_t line() const noexcept { return _M_line; }
  57. constexpr uint_least32_t column() const noexcept { return _M_col; }
  58. constexpr const char* file_name() const noexcept { return _M_file; }
  59. constexpr const char* function_name() const noexcept { return _M_func; }
  60. private:
  61. const char* _M_file;
  62. const char* _M_func;
  63. uint_least32_t _M_line;
  64. uint_least32_t _M_col;
  65. };
  66. } // namespace fundamentals_v2
  67. } // namespace experimental
  68. _GLIBCXX_END_NAMESPACE_VERSION
  69. } // namespace std
  70. #endif