Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Blog
read_write_lock_acc
#include <iostream> #include <algorithm> struct AB { int x = 1; double y = 100.; }; typedef int read_lock; typedef double write_lock; template<typename LockType, typename ABType> class X : public ABType{ public: typedef const ABType& access_type; }; template<typename ABType> class X<write_lock, ABType> : public ABType{ public: typedef ABType& access_type; }; template<typename LockType> struct XY:protected X<LockType, AB>{ template<typename WeightType> std::enable_if_t<std::is_floating_point<WeightType>::value, WeightType> value() const { return (WeightType)X<LockType, AB>::y; } template<typename WeightType> std::enable_if_t<std::is_integral<WeightType>::value, WeightType> value() const { return X<LockType, AB>::x; } typedef typename X<LockType, AB>::access_type access_type; operator access_type(){ return *this; } access_type data(){ return *this; } }; int main(int, char**) { XY<write_lock> xy; std::cout << xy.value<float>() << std::endl << xy.value<short>() << std::endl; AB& ab = xy; //const AB& ab = xy.data(); AB& ab = xy.data(); return 0; }
run
|
edit
|
history
|
help
0
Please
log in
to post a comment.
My Tuple class
pm zn moer 2.0
RCP 27
Coin changes
Raw AVL
char pointer in class
function pointer overload
map_find
test
PayTax
stackse - search stackoverflow differently
Please log in to post a comment.