Giter Site home page Giter Site logo

jimmy-park / singleton Goto Github PK

View Code? Open in Web Editor NEW
24.0 24.0 1.0 96 KB

C++11/17/20 thread-safe singleton pattern using CRTP

License: MIT License

C++ 51.64% CMake 48.36%
cmake cpp cpp11 cpp17 cpp20 crtp dclp design-pattern header-only singleton singleton-pattern

singleton's People

Contributors

dependabot[bot] avatar jimmy-park avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

darallium

singleton's Issues

How to start a thread with a singleton class's member function?

I tried the following code, but it did not work:

class WebsocketManager : public SingletonDclp<WebsocketManager> {
    // ...
    void sendAction(types::WsAction action);

    void sendAction(types::WsAction action, nlohmann::json&& data);
}

enum class WsAction {
    CompletionAccept,
    CompletionCache,
    CompletionCancel,
    CompletionGenerate,
    DebugSync,
};

// Failed to compile
thread(&WebsocketManager::sendAction, WebsocketManager::GetInstance(), WsAction::CompletionCancel).detach();

The compile log is:

C:\xxxx\CompletionManager.cc(246): error C2440: '<function-style-cast>': cannot convert from 'initializer list' to 'std::thread'
C:\xxxx\CompletionManager.cc(246): note: 'std::thread::thread': function does not take 3 arguments
C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.38.33130\include\thread(92): note: could be 'std::thread::thread(_Fn &&,_Args &&...)'
C:\xxxx\CompletionManager.cc(246): note: while trying to match the argument list '(overloaded-function, Derived *, types::WsAction)'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.