include/comphelper/propertyvalue.hxx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
New commits: commit 23cded985ba0131f85ee445492c04871fbfb6351 Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Sun Oct 17 10:02:17 2021 +0200 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Sun Oct 17 14:36:51 2021 +0200 Specialize comphelper::makePropertyValue for arithmetic types This allows to pass e.g. bit fields to the function, like struct Foo { bool b : 1; }; Foo foo {true}; comphelper::makePropertyValue("foo", foo.b); Change-Id: I8f725d0101d90fb8b6012375c085918d1cadc6f1 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/123639 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> diff --git a/include/comphelper/propertyvalue.hxx b/include/comphelper/propertyvalue.hxx index ac4f6886039e..9d0d94d3256a 100644 --- a/include/comphelper/propertyvalue.hxx +++ b/include/comphelper/propertyvalue.hxx @@ -12,6 +12,7 @@ #include <sal/config.h> +#include <type_traits> #include <utility> #include <com/sun/star/beans/PropertyValue.hpp> @@ -25,11 +26,18 @@ namespace comphelper * * instead of writing 3 extra lines to set the name and value of the beans::PropertyValue. */ -template <typename T> css::beans::PropertyValue makePropertyValue(const OUString& rName, T&& rValue) +template <typename T, std::enable_if_t<!std::is_arithmetic_v<std::remove_reference_t<T>>, int> = 0> +css::beans::PropertyValue makePropertyValue(const OUString& rName, T&& rValue) { return { rName, 0, css::uno::toAny(std::forward<T>(rValue)), css::beans::PropertyState_DIRECT_VALUE }; } +// Allows to pass e.g. bit fields +template <typename T, std::enable_if_t<std::is_arithmetic_v<std::remove_reference_t<T>>, int> = 0> +css::beans::PropertyValue makePropertyValue(const OUString& rName, T aValue) +{ + return makePropertyValue(rName, css::uno::toAny(aValue)); +} } #endif // INCLUDED_COMPHELPER_PROPERTYVALUE_HXX