dalzhim / articleenumclass-v2 Goto Github PK
View Code? Open in Web Editor NEWHome Page: https://dalzhim.github.io/2017/08/11/Improving-the-enum-class-bitmask/
License: BSD 2-Clause "Simplified" License
Home Page: https://dalzhim.github.io/2017/08/11/Improving-the-enum-class-bitmask/
License: BSD 2-Clause "Simplified" License
I really like the elegant simplicity achieved by your enum classes!
However, I got stuck on a problem using them in templates. The following code inspired by ATL CWinTraits fails. Any idea of a solution?
enum class ServiceHandler : uint16_t
{
accept_none = 0u,
accept_stop = SERVICE_ACCEPT_STOP,
accept_pausecontinue = SERVICE_ACCEPT_PAUSE_CONTINUE,
accept_shutdown = SERVICE_ACCEPT_SHUTDOWN,
accept_paramchange = SERVICE_ACCEPT_PARAMCHANGE,
accept_netbindchange = SERVICE_ACCEPT_NETBINDCHANGE,
accept_hardwareprofilechange = SERVICE_ACCEPT_HARDWAREPROFILECHANGE,
accept_powerevent = SERVICE_ACCEPT_POWEREVENT,
accept_sessionchange = SERVICE_ACCEPT_SESSIONCHANGE,
accept_preshutdown = SERVICE_ACCEPT_PRESHUTDOWN,
accept_timechange = SERVICE_ACCEPT_TIMECHANGE,
accept_triggerevent = SERVICE_ACCEPT_TRIGGEREVENT,
accept_userlogoff = SERVICE_ACCEPT_USER_LOGOFF,
accept_lowresources = SERVICE_ACCEPT_LOWRESOURCES,
accept_systemlowresources = SERVICE_ACCEPT_SYSTEMLOWRESOURCES
};
enableEnumClassBitmask(ServiceHandler);
template <ServiceHandler Taccepttraits = ServiceHandler::accept_none>
class ServiceAcceptTraits
{
public:
ServiceHandler GetAcceptTraits(void) const noexcept { return Taccepttraits; }
};
using StandardAcceptTraits = ServiceAcceptTraits<
ServiceHandler::accept_stop
| ServiceHandler::accept_pausecontinue
| ServiceHandler::accept_shutdown>;
This is intended to be used like so:
template <
class TderivedClass,
const wchar_t* Tservicename,
class TServiceAcceptTraits = StandardAcceptTraits>
class NO_VTABLE ServiceBase
{
};
compilation gives
error C2440: 'specialization': cannot convert from 'bitmask<ServiceHandler>' to 'ServiceHandler'
Hi,
I have a problem when declaring enableEnumClassBitmask within some namespace.
namespace sth
{
enum class masks
{
MASK_1 = 0x01,
...
};
enableEnumClassBitmask(masks);
}
Compilers (gcc/clang) complain about specializing struct enable_enum_class_bitmask
in some other namespace than it was previously declared (global namespace, when #included).
Macro enableEnumClassBitmask
should declare this specialization in the global namespace, but trying to use struct ::enable_enum_class_bitmask<T>
also gives an error.
Any ideas how to solve that issue?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.