From 649313625b94e6b879848fc19b607b74375100bf Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Thu, 17 May 2018 11:28:56 +0200 Subject: 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 Tested-by: Stephan Bergmann --- include/o3tl/temporary.hxx | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 include/o3tl/temporary.hxx (limited to 'include/o3tl') 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 + +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 constexpr T& temporary(T&& x) { return x; } +template constexpr T& temporary(T&) = delete; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ -- cgit v1.2.3