Skip to content

Instantly share code, notes, and snippets.

@martinmoene
Last active December 14, 2020 06:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martinmoene/73a7e15acc015c7038ef7c6f1a7ffb81 to your computer and use it in GitHub Desktop.
Save martinmoene/73a7e15acc015c7038ef7c6f1a7ffb81 to your computer and use it in GitHub Desktop.
Tweak-header, A New Approach to Build-Time Library Configuration, by Colby Pike aka vector-of-bool. Oct 4, 2020
// Tweak-header, A New Approach to Build-Time Library Configuration,
// by Colby Pike aka vector-of-bool. Oct 4, 2020
// https://vector-of-bool.github.io/2020/10/04/lib-configuration.html
#include <cstdlib>
#include <string>
namespace program { namespace config {
namespace defaults
{
constexpr bool do_audit() noexcept
{
return false;
}
inline bool do_audit_rt() noexcept
{
auto ev = std::getenv("PROGRAM_TWEAK_AUDIT");
return ev && std::string(ev) != "0";
}
}
using namespace defaults;
}}
// __has_include() is part of the C++17 standard, g++ supports it since v5
// https://en.cppreference.com/w/cpp/compiler_support#cpp17
#ifdef __has_include
# if __has_include("program.tweak.hpp")
# include "program.tweak.hpp"
# endif
#else
# pragma message("program.config.hpp: Note: Tweak header not supported.")
#endif
// Tweak-header, A New Approach to Build-Time Library Configuration,
// by Colby Pike aka vector-of-bool. Oct 4, 2020
// https://vector-of-bool.github.io/2020/10/04/lib-configuration.html
#include "program.config.hpp"
#include <iostream>
int main()
{
std::cout << std::boolalpha <<
"program: do_audit():" << program::config::do_audit() <<
" do_audit_rt():" << program::config::do_audit_rt() << '\n';
}
// g++ -Wall -std=c++11 -o program.exe program.cpp && program.exe
// Tweak-header, A New Approach to Build-Time Library Configuration,
// by Colby Pike aka vector-of-bool. Oct 4, 2020
// https://vector-of-bool.github.io/2020/10/04/lib-configuration.html
namespace program { namespace config {
constexpr bool do_audit() noexcept
{
return true;
}
}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment