Namespaces
Variants

std::source_location::source_location

출처: ko.cppreference.net
 
 
유틸리티 라이브러리
일반 유틸리티
관계 연산자 (C++20에서 사용 중단)
정수 비교 함수
(C++20)(C++20)(C++20)    
(C++20)
스왑 및 타입 연산
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
공통 어휘 타입
(C++11)
(C++17)
(C++17)
(C++17)
(C++11)
(C++17)
(C++23)



 
 
constexpr source_location() noexcept;
(1) (C++20부터)
source_location( const source_location& other );
(2) (C++20부터)
source_location( source_location&& other ) noexcept;
(3) (C++20부터)
1) 지정되지 않은 값을 가진 source_location 객체를 생성합니다.
2,3) 복사 생성자 및 이동 생성자입니다. 이들이 trivial 및/또는 constexpr인지는 명시되지 않습니다.

매개변수

other - 복사하거나 이동할 다른 source_location 객체

예제

#include <iomanip>
#include <iostream>
#include <ranges>
#include <source_location>
#include <string_view>
#include <vector>
// GCC 전용 타입 이름 출력기
#if (__GNUG__ >= 11)
template<typename T>
auto type_name_helper(const std::source_location s = std::source_location::current())
{
    using std::operator""sv;
    const std::string_view fun_name{s.function_name()};
    constexpr auto prefix{"[with T = "sv};
    const auto type_name_begin{fun_name.find(prefix)};
    if (""sv.npos == type_name_begin)
        return ""sv;
    const std::size_t first{type_name_begin + prefix.length()};
    return std::string_view{fun_name.cbegin() + first, fun_name.cend() - 1};
}
template<typename T>
auto type_name() { return type_name_helper<T>(); }
#endif
void print(std::string_view const comment, std::source_location const l)
{
    std::cout << comment << ":\n"
              << "  file_name     : " << std::quoted(l.file_name()) << '\n'
              << "  function_name : " << std::quoted(l.function_name()) << '\n'
              << "  line          : " << l.line() << '\n'
              << "  column        : " << l.column() << '\n';
}
int main()
{
    constexpr std::source_location default_constructed;
    print("기본 생성됨", default_constructed);
    constexpr std::source_location current = std::source_location::current();
    print("현재 위치", current);
#if (__GNUG__ >= 11)
    const std::vector<std::vector<int>> v{{1,2}, {3,4,5}, {6}};
    auto jv = std::ranges::join_view(v);
    std::cout << '\n'
              << '[' << type_name<int>() << "]\n"
              << '[' << type_name<double*>() << "]\n"
              << '[' << type_name<decltype([](){})>() << "]\n"
              << '[' << type_name<decltype(type_name<int>())>() << "]\n"
              << '[' << type_name<decltype(jv)>() << "]\n";
#endif
}

가능한 출력:

기본 생성:
  file_name     : ""
  function_name : ""
  line          : 0
  column        : 0
현재:
  file_name     : "main.cpp"
  function_name : "int main()"
  line          : 39
  column        : 75
[int]
[double*]
[main()::<lambda()>]
[std::basic_string_view<char>]
[std::ranges::join_view<std::ranges::ref_view<const std::vector<std::vector<int> > > >]

참고 항목

[static]
호출 지점의 위치에 해당하는 새로운 source_location 를 생성함
(public static member function)
새로운 stacktrace_entry 를 생성함
(public member function of std::stacktrace_entry )