From 8dfe07b5b54e5ba4147545407cdc1f422e753861 Mon Sep 17 00:00:00 2001 From: Yuriy Skalko Date: Sat, 21 Nov 2020 16:27:13 +0200 Subject: [PATCH] Use `std::any` when compiler supports C++17 or later --- src/insets/ExternalTransforms.cpp | 4 ++-- src/insets/ExternalTransforms.h | 7 +++---- src/support/Makefile.am | 1 + src/support/any.h | 23 +++++++++++++++++++++++ 4 files changed, 29 insertions(+), 6 deletions(-) create mode 100644 src/support/any.h diff --git a/src/insets/ExternalTransforms.cpp b/src/insets/ExternalTransforms.cpp index 4f85f9d479..9ff5772cd9 100644 --- a/src/insets/ExternalTransforms.cpp +++ b/src/insets/ExternalTransforms.cpp @@ -326,13 +326,13 @@ string const sanitizeLatexOption(string const & input) namespace { template -void extractIt(boost::any const & any_factory, +void extractIt(any const & any_factory, Data const & data, Transformer & transformer) { if (any_factory.type() != typeid(Factory)) return; - Factory factory = boost::any_cast(any_factory); + Factory factory = any_cast(any_factory); if (factory) transformer = factory(data); } diff --git a/src/insets/ExternalTransforms.h b/src/insets/ExternalTransforms.h index 8b22f622c8..62e3342352 100644 --- a/src/insets/ExternalTransforms.h +++ b/src/insets/ExternalTransforms.h @@ -14,11 +14,10 @@ #include "graphics/GraphicsParams.h" +#include "support/any.h" #include "support/Length.h" #include "support/unique_ptr.h" -#include - #include #include #include @@ -339,7 +338,7 @@ public: */ template TransformStore(TransformID id_, Factory const & factory) - : id(id_), any_factory(boost::any(factory)) {} + : id(id_), any_factory(any(factory)) {} typedef TransformCommand::ptr_type ComPtr; typedef TransformOption::ptr_type OptPtr; @@ -353,7 +352,7 @@ public: private: TransformID id; - boost::any any_factory; + any any_factory; }; } // namespace external diff --git a/src/support/Makefile.am b/src/support/Makefile.am index 45d30b823f..4ff8618129 100644 --- a/src/support/Makefile.am +++ b/src/support/Makefile.am @@ -35,6 +35,7 @@ liblyxsupport_a_SOURCES = \ FileMonitor.h \ FileMonitor.cpp \ RandomAccessList.h \ + any.h \ bind.h \ Cache.h \ Changer.h \ diff --git a/src/support/any.h b/src/support/any.h new file mode 100644 index 0000000000..e8f6a111fb --- /dev/null +++ b/src/support/any.h @@ -0,0 +1,23 @@ +// -*- C++ -*- +/** + * \file any.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Yuriy Skalko + * + * Full author contact details are available in file CREDITS. + */ + +#ifndef LYX_ANY_H +#define LYX_ANY_H + +#if __cplusplus >= 201703L + #include + namespace lyx { using std::any; } +#else + #include + namespace lyx { using boost::any; } +#endif + +#endif // LYX_ANY_H -- 2.39.5