Last active
October 6, 2026 22:43
-
-
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!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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