// Copyright (c) Sleipnir contributors

#pragma once

#ifdef SLEIPNIR_PYTHON
#include <source_location>
#include <stdexcept>

#include <fmt/format.h>

/// Throws an exception in Python.
#define slp_assert(condition)                                        \
  do {                                                               \
    if (!(condition)) {                                              \
      auto location = std::source_location::current();               \
      throw std::invalid_argument(fmt::format(                       \
          "{}:{}: {}: Assertion `{}' failed.", location.file_name(), \
          location.line(), location.function_name(), #condition));   \
    }                                                                \
  } while (0)
#else
#include <cassert>

/// Aborts in C++.
#define slp_assert(condition) assert(condition)
#endif
