TemplateParameter.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  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. #pragma warning(suppress: 4189) // C4189: local variable is initialized but not referenced
  19. Base *const b = t;
  20. }
  21. public:
  22. SameOrDerivedFrom()
  23. {
  24. #pragma warning(suppress: 4189) // C4189: local variable is initialized but not referenced
  25. void (*const p)(T *const t) = Constrain;
  26. }
  27. };
  28. template<class T>
  29. struct Box
  30. {
  31. };
  32. };