Skip to content

Instantly share code, notes, and snippets.

@unrays
Last active October 6, 2026 22:43
Show Gist options
  • Select an option

  • Save unrays/014452e4dd18885b5ef3f07690fcb85f to your computer and use it in GitHub Desktop.

Select an option

Save unrays/014452e4dd18885b5ef3f07690fcb85f to your computer and use it in GitHub Desktop.
The Exotic Library API Idiom: a simple structure for separating internals from the public interface. Yeah, I really love naming things!
// Copyright (c) October 2026 Félix-Olivier Dumas. All rights reserved.
// Licensed under the terms described in the LICENSE file
namespace exotic::internal::foo {
namespace detail {
template<typename T>
struct impl {
using value_type = T;
void run();
};
}
namespace api {
// generic API
template<typename T>
struct custom : detail::impl<T> {};
// specialized APIs can be added here
struct standard : custom<int> {};
}
}
// public facade
namespace exotic {
template<typename T>
using foo = internal::foo::api::custom<T>;
using standard_foo = internal::foo::api::standard;
}
// user code only sees the facade :)
exotic::foo<float> a;
exotic::standard_foo b;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment