make source location happy on macos

* because of course apple doesn't provide any implementation (lmao) we provide one ourself
This commit is contained in:
jeff 2021-05-11 07:53:32 -04:00 committed by Jeff Becker
parent 5c457ff486
commit 0546dab2e3
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

View File

@ -4,6 +4,69 @@
#include <source_location>
namespace slns = std;
#else
#ifdef __APPLE__
namespace slns
{
struct source_location
{
public:
static constexpr source_location
current(
const char* fileName = __builtin_FILE(),
const char* functionName = __builtin_FUNCTION(),
const uint_least32_t lineNumber = __builtin_LINE(),
const uint_least32_t columnOffset = __builtin_COLUMN()) noexcept
{
return source_location{fileName, functionName, lineNumber, columnOffset};
}
source_location(const source_location&) = default;
source_location(source_location&&) = default;
constexpr const char*
file_name() const noexcept
{
return fileName;
}
constexpr const char*
function_name() const noexcept
{
return functionName;
}
constexpr uint_least32_t
line() const noexcept
{
return lineNumber;
}
constexpr std::uint_least32_t
column() const noexcept
{
return columnOffset;
}
private:
constexpr explicit source_location(
const char* fileName,
const char* functionName,
const uint_least32_t lineNumber,
const uint_least32_t columnOffset) noexcept
: fileName(fileName)
, functionName(functionName)
, lineNumber(lineNumber)
, columnOffset(columnOffset)
{}
const char* fileName;
const char* functionName;
const std::uint_least32_t lineNumber;
const std::uint_least32_t columnOffset;
};
} // namespace slns
#else
#include <experimental/source_location>
namespace slns = std::experimental;
#endif
#endif