base_types.hpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /* Copyright 2016-2018 Joaquin M Lopez Munoz.
  2. * Distributed under the Boost Software License, Version 1.0.
  3. * (See accompanying file LICENSE_1_0.txt or copy at
  4. * http://www.boost.org/LICENSE_1_0.txt)
  5. *
  6. * See http://www.boost.org/libs/poly_collection for library home page.
  7. */
  8. #ifndef BOOST_POLY_COLLECTION_TEST_BASE_TYPES_HPP
  9. #define BOOST_POLY_COLLECTION_TEST_BASE_TYPES_HPP
  10. #if defined(_MSC_VER)
  11. #pragma once
  12. #endif
  13. #include <boost/poly_collection/base_collection.hpp>
  14. namespace base_types{
  15. struct base
  16. {
  17. virtual ~base()=default;
  18. virtual int operator()(int)const=0;
  19. };
  20. struct derived1 final:base
  21. {
  22. derived1(int n):n{n}{}
  23. derived1(derived1&&)=default;
  24. derived1(const derived1&)=delete;
  25. derived1& operator=(derived1&&)=default;
  26. derived1& operator=(const derived1&)=delete;
  27. virtual int operator()(int)const{return n;}
  28. bool operator==(const derived1& x)const{return n==x.n;}
  29. int n;
  30. };
  31. struct derived2:base
  32. {
  33. derived2(int n):n{n}{}
  34. derived2(derived2&&)=default;
  35. derived2& operator=(derived2&&)=delete;
  36. virtual int operator()(int x)const{return x*n;}
  37. bool operator==(const derived2& x)const{return n==x.n;}
  38. int n;
  39. };
  40. struct derived3:base
  41. {
  42. derived3():n{-1}{}
  43. derived3(int n):n{n}{}
  44. virtual int operator()(int x)const{return x*x*n;}
  45. int n;
  46. };
  47. struct another_base
  48. {
  49. virtual ~another_base()=default;
  50. char x[5];
  51. };
  52. struct derived4:another_base,derived3
  53. {
  54. using derived3::derived3;
  55. virtual int operator()(int x)const{return -(this->derived3::operator()(x));}
  56. bool operator==(const derived4& x)const{return n==x.n;}
  57. };
  58. struct derived5:base,another_base
  59. {
  60. derived5(int n):n{n}{}
  61. virtual int operator()(int x)const{return x*x*x*n;}
  62. int n;
  63. };
  64. using collection=boost::base_collection<base>;
  65. using t1=derived1;
  66. using t2=derived2;
  67. using t3=derived3;
  68. using t4=derived4;
  69. using t5=derived5;
  70. struct to_int
  71. {
  72. template<typename F>
  73. int operator()(const F& f)const{return f(1);}
  74. };
  75. } /* namespace base_types */
  76. #endif