Motivation
The Basis represent an abstract mathematical object that is unique, in the sense that it only provide the evaluations of objects that do not change. In the same sense, they must not have a state. Basis are stateless. I have used mutable private variables to improve performance and avoid creating new objects.
Because its abstract and unique nature, Basis must exists in a unique non writable instance.
Proposed solution
class Base {};
template <typename Current> class Helper {
public:
template <typename... Ts> static std::shared_ptr<Current> get(Ts &&... args) {
auto const values{std::make_tuple(args...)};
static std::map<std::tuple<Ts...>, std::shared_ptr<Current>> database;
if (database.find(values) == database.end()) {
database[values] = std::make_shared<Current>(args...);
}
return database[values];
}
};
int main() { return 0; }
Motivation
The
Basisrepresent an abstract mathematical object that is unique, in the sense that it only provide the evaluations of objects that do not change. In the same sense, they must not have a state. Basis are stateless. I have used mutable private variables to improve performance and avoid creating new objects.Because its abstract and unique nature,
Basismust exists in a unique non writable instance.Proposed solution