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