variant_collection.hpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* Copyright 2024 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_VARIANT_COLLECTION_HPP
  9. #define BOOST_POLY_COLLECTION_VARIANT_COLLECTION_HPP
  10. #if defined(_MSC_VER)
  11. #pragma once
  12. #endif
  13. #include <boost/poly_collection/variant_collection_fwd.hpp>
  14. #include <boost/mp11/list.hpp>
  15. #include <boost/poly_collection/detail/variant_model.hpp>
  16. #include <boost/poly_collection/detail/poly_collection.hpp>
  17. #include <utility>
  18. namespace boost{
  19. namespace poly_collection{
  20. template<typename TypeList,typename Allocator>
  21. class variant_collection:
  22. public common_impl::poly_collection<
  23. mp11::mp_rename<TypeList,detail::variant_model>,Allocator>
  24. {
  25. using base_type=common_impl::poly_collection<
  26. mp11::mp_rename<TypeList,detail::variant_model>,Allocator>;
  27. base_type& base()noexcept{return *this;}
  28. const base_type& base()const noexcept{return *this;}
  29. public:
  30. using base_type::base_type;
  31. variant_collection()=default;
  32. variant_collection(const variant_collection& x)=default;
  33. variant_collection(variant_collection&& x)=default;
  34. variant_collection& operator=(const variant_collection& x)=default;
  35. variant_collection& operator=(variant_collection&& x)=default;
  36. template<typename TL,typename A>
  37. friend bool operator==(
  38. const variant_collection<TL,A>&,const variant_collection<TL,A>&);
  39. };
  40. template<typename TypeList,typename Allocator>
  41. bool operator==(
  42. const variant_collection<TypeList,Allocator>& x,
  43. const variant_collection<TypeList,Allocator>& y)
  44. {
  45. return x.base()==y.base();
  46. }
  47. template<typename TypeList,typename Allocator>
  48. bool operator!=(
  49. const variant_collection<TypeList,Allocator>& x,
  50. const variant_collection<TypeList,Allocator>& y)
  51. {
  52. return !(x==y);
  53. }
  54. // TODO: other rel operators?
  55. template<typename TypeList,typename Allocator>
  56. void swap(
  57. variant_collection<TypeList,Allocator>& x,
  58. variant_collection<TypeList,Allocator>& y)
  59. {
  60. x.swap(y);
  61. }
  62. } /* namespace */
  63. using poly_collection::variant_collection;
  64. } /* namespace boost */
  65. #endif