Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Impl.h
- #pragma once
- struct A {
- struct {
- int value;
- } valueA;
- };
- struct B {
- struct {
- int value;
- } valueB;
- };
- template<typename T>
- int GetValue(T const &value);
- // Impl.cpp
- #include "Impl.h"
- #include <type_traits>
- using std::enable_if_t;
- using std::remove_reference_t;
- template<typename T, typename U, U(T::*Value)>
- static inline int GetValueImpl(T const &value) {
- return (value.*Value).value;
- }
- template<typename T>
- enable_if_t<T::valueA, int> GetValue(T const &value) {
- static constexpr auto T::*const Value = &T::valueA;
- typedef remove_reference_t<decltype(value.*Value)> ValueType;
- return GetValueImpl<T, ValueType, Value>(value);
- }
- template<typename T>
- enable_if_t<T::valueB, int> GetValue(T const &value) {
- static constexpr auto T::*const Value = &T::valueB;
- typedef remove_reference_t<decltype(value.*Value)> ValueType;
- return GetValueImpl<T, ValueType, Value>(value);
- }
- template<> int GetValue(A const &); // C2912 here
- template<> int GetValue(B const &); // C2912 here
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement