'can c++ class attributes be conditionally compiled
Say I want to make 2 versions of a class - a thread safe version which will use lock guards on all mutating operations, and a 'thread dangerous' one which won't and will presumably run faster in a single-threaded client.
A bit like this:
#include <type_traits>
#include <mutex>
template <bool THREADSAFE>
class wibble {
private:
typename std::enable_if<THREADSAFE, std::mutex>::type mtx_;
};
wibble<true> threadsafe; // ok
wibble<false> thread_dangerous; // compiler error
Thanks!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
