source_location


1. Getting the Source Location of a Function

#include <iostream>
#include <string>

int main() {
  auto source_location = __builtin_return_address(0);
  auto function_name = source_location->function_name;
  auto filename = source_location->file_name;
  auto line_number = source_location->line_number;

  std::cout << "Function: " << function_name << std::endl;
  std::cout << "File: " << filename << std::endl;
  std::cout << "Line: " << line_number << std::endl;

  return 0;
}

2. Logging Source Location with GOOGLE_LOG(Google Logging Library)

#include <glog/logging.h>

int main() {
  LOG(INFO) << "Source location: " << __FILE__ << ":" << __LINE__;
  return 0;
}

3. Error Handling with Source Location

4. Customizing Exception Behavior with Source Location

5. Debugging and Profiling with Source Location

6. Source Location in Unit Tests

7. Logging with Timestamp and Source Location

8. Source Location in Debug Logs

9. Exception Handling with Source Location and Backtrace

10. Source Location in Template Metaprogramming

11. Source Location in Macros

12. Source Location in Conditional Compilation

13. Source Location in C++20 Concepts

14. Source Location in Lambdas

15. Source Location in Exception Handling

16. Source Location in Templates with Variable Templates

17. Source Location in Function Pointers

18. Source Location in Lambda Expressions

19. Source Location in Variadic Templates

20. Source Location in Macros with Variable Arguments

21. Source Location in Exception Handling with Stack Unwinding

22. Source Location in Template Metaprogramming with Fold Expressions

23. Source Location in Library Functions

24. Source Location in Function Pointers with Anonymous Functions

25. Source Location in Generic Programming with Type Traits

26. Source Location in User-Defined Literals

27. Source Location in Compile-Time Function Evaluation

28. Source Location in Template Metaprogramming with SFINAE

29. Source Location in Variadic Macros

30. Source Location in Exception Handling with Nested Exceptions

31. Source Location in Template Metaprogramming with Recursive Functions

32. Source Location in Lambda Expressions with Captures

33. Source Location in Macros with Stringification

34. Source Location in Function Pointers with Static Functions

35. Source Location in Template Metaprogramming with Class Templates

36. Source Location in Exception Handling with Custom Exception Classes

37. Source Location in Function Pointers with Member Functions

38. Source Location in Template Metaprogramming with Fold Expressions and Strings

39. Source Location in Macros with Variable Arguments and Stringification

40. Source Location in Exception Handling with Stack Unwinding and Custom Exception Classes

41. Source Location in Function Pointers with Nested Functions

42. Source Location in Lambdas with Captures and Default Arguments

43. Source Location in Macros with Stringification and Variable Arguments

44. Source Location in Template Metaprogramming with Fold Expressions and Class Templates

45. Source Location in Variadic Function Templates

46. Source Location in Function Pointers with Member Functions and Nested Classes

47. Source Location in Template Metaprogramming with Class Templates and Fold Expressions

48. Source Location in Variadic Macros with Default Arguments

49. Source Location in Function Pointers with Lambda Expressions

50. Source Location in Template Metaprogramming with Fold Expressions and SFINAE