TemplateParameter.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. #pragma once
  6. // -----------------------------------------------------------------------------------------------------------------------------
  7. // Template parameter constraints
  8. // See http://www.stroustrup.com/bs_faq2.html#constraints
  9. // -----------------------------------------------------------------------------------------------------------------------------
  10. namespace TemplateParameter
  11. {
  12. template<class T, class Base>
  13. class SameOrDerivedFrom
  14. {
  15. private:
  16. static void Constrain(T *const t)
  17. {
  18. CLANG_WNO_BEGIN("-Wunused-variable")
  19. #pragma warning(suppress: 4189) // C4189: local variable is initialized but not referenced
  20. Base *const b = t;
  21. CLANG_WNO_END
  22. }
  23. public:
  24. SameOrDerivedFrom()
  25. {
  26. CLANG_WNO_BEGIN("-Wunused-variable")
  27. #pragma warning(suppress: 4189) // C4189: local variable is initialized but not referenced
  28. void (*const p)(T *const t) = Constrain;
  29. CLANG_WNO_END
  30. }
  31. };
  32. template<class T>
  33. struct Box
  34. {
  35. };
  36. };