workaround segfault in compiler on macos-clang-intel
[LibreOffice.git] / include / svl / typedwhich.hxx
blobe96ad8228d5c2e29113b1c379677b0fe374c6810
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
9 #ifndef INCLUDED_SVL_TYPEDWHICH_HXX
10 #define INCLUDED_SVL_TYPEDWHICH_HXX
12 #include <sal/config.h>
13 #include <sal/types.h>
14 #include <type_traits>
16 /**
17 * A very thin wrapper around the sal_uInt16 WhichId whose purpose is mostly to carry type information,
18 * so that we Put() and Get() the right subclasses of SfxPoolItem for each WhichId.
20 template <class T> class TypedWhichId final
22 public:
23 explicit constexpr TypedWhichId(sal_uInt16 nWhich)
24 : mnWhich(nWhich)
28 /** Up-casting conversion constructor
30 template <class derived_type>
31 constexpr TypedWhichId(TypedWhichId<derived_type> other,
32 std::enable_if_t<std::is_base_of_v<T, derived_type>, int> = 0)
33 : mnWhich(sal_uInt16(other))
37 constexpr operator sal_uInt16() const { return mnWhich; }
39 private:
40 sal_uInt16 mnWhich;
43 template <class T> constexpr bool operator==(TypedWhichId<T> const& lhs, TypedWhichId<T> rhs)
45 return sal_uInt16(lhs) == sal_uInt16(rhs);
47 template <class T> constexpr bool operator!=(TypedWhichId<T> const& lhs, TypedWhichId<T> rhs)
49 return sal_uInt16(lhs) != sal_uInt16(rhs);
51 template <class T> constexpr bool operator==(sal_uInt16 lhs, TypedWhichId<T> const& rhs)
53 return lhs == sal_uInt16(rhs);
55 template <class T> constexpr bool operator!=(sal_uInt16 lhs, TypedWhichId<T> const& rhs)
57 return lhs != sal_uInt16(rhs);
59 template <class T> constexpr bool operator==(TypedWhichId<T> const& lhs, sal_uInt16 rhs)
61 return sal_uInt16(lhs) == rhs;
63 template <class T> constexpr bool operator!=(TypedWhichId<T> const& lhs, sal_uInt16 rhs)
65 return sal_uInt16(lhs) != rhs;
68 #endif // INCLUDED_SVL_TYPEDWHICH_HXX
70 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */