diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2021-10-17 10:02:17 +0200 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2021-10-17 14:36:51 +0200 |
commit | 23cded985ba0131f85ee445492c04871fbfb6351 (patch) | |
tree | 9690bcf499d46aa2381817720db6bf2602265364 /include/comphelper | |
parent | Simplify comphelper::makePropertyValue (diff) | |
download | core-23cded985ba0131f85ee445492c04871fbfb6351.tar.gz core-23cded985ba0131f85ee445492c04871fbfb6351.zip |
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.kaganski@collabora.com>
Diffstat (limited to 'include/comphelper')
-rw-r--r-- | include/comphelper/propertyvalue.hxx | 10 |
1 files changed, 9 insertions, 1 deletions
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 |