Skip to content

Make Basis singleton #40

@rafaelrojasmiliani

Description

@rafaelrojasmiliani

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; }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions