diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2018-05-17 11:28:56 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2018-05-17 21:03:12 +0200 |
commit | 649313625b94e6b879848fc19b607b74375100bf (patch) | |
tree | daa8993fe967cbfdad18aabac1635f7ded1977c2 /include/o3tl | |
parent | 3a667101987ccbc75024942d779c8c62a4d0a296 (diff) |
New o3tl::temporary to simplify calls of std::modf
...that ignore the out-parameter integral part
Change-Id: I05f07c1a8909023232f8aecf75ea5541d4eb81ca
Reviewed-on: https://gerrit.libreoffice.org/54474
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Tested-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'include/o3tl')
-rw-r--r-- | include/o3tl/temporary.hxx | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/include/o3tl/temporary.hxx b/include/o3tl/temporary.hxx new file mode 100644 index 000000000000..476e934cb44a --- /dev/null +++ b/include/o3tl/temporary.hxx @@ -0,0 +1,22 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <sal/config.h> + +namespace o3tl +{ +// Cast an rvalue to an lvalue. Can be useful if a function parameter is a pointer/reference to T, +// and some call site doesn't need the value beyond the call itself (e.g., in a call like +// std::modf(x, &o3tl::temporary(double())) to obtain the fractional part of x, ignoring the +// integral part). +template <typename T> constexpr T& temporary(T&& x) { return x; } +template <typename T> constexpr T& temporary(T&) = delete; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ |