nkr
A C++20 library with a custom meta-programming language.
Namespaces
nkr::interface Namespace Reference

Interfaces provide a small abstraction over different entities so that they can be utilized in the same way. More...

Namespaces

namespace  none
 None interfaces handle semantics revolving around the lack of something.
 

Detailed Description

Interfaces provide a small abstraction over different entities so that they can be utilized in the same way.

Interfaces are usually introduced when working with generics so that syntactically different entities that are otherwise semantically similar or equivalent can be treated with the same syntax. Put another way, interfaces help to avoid unnecessary constraints on program design and thus directly increase the robustness of code.

For example, nkr::interface::none::value_i can return a none value for a type that doesn't have a default constructor or for a type that does have a default constructor but which doesn't default its type instances to a value that can be equated to none. Importantly, because this interface must be opted into, this allows the designer of an entity to avoid having to fulfill the concept of none when it doesn't make sense, or if they simpy want to avoid using the concept of none according to design principles. For a concrete example, please see nkr::interface::none::value_i.

There is a cost to using interfaces and it is two fold:

  1. Designers of entities almost always have to opt into an interface if they want their entity to be useful with it, and thus they need to make implementations which can run up development time.
  2. Although run-time is almost never (if not actually never) affected, compile-time increases due to the extra template abstractions.