Use std::any when compiler supports C++17 or later

This commit is contained in:
Yuriy Skalko 2020-11-21 16:27:13 +02:00
parent cbad214cdd
commit 8dfe07b5b5
4 changed files with 29 additions and 6 deletions

View File

@ -326,13 +326,13 @@ string const sanitizeLatexOption(string const & input)
namespace {
template <typename Factory, typename Data, typename Transformer>
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<Factory>(any_factory);
Factory factory = any_cast<Factory>(any_factory);
if (factory)
transformer = factory(data);
}

View File

@ -14,11 +14,10 @@
#include "graphics/GraphicsParams.h"
#include "support/any.h"
#include "support/Length.h"
#include "support/unique_ptr.h"
#include <boost/any.hpp>
#include <functional>
#include <map>
#include <memory>
@ -339,7 +338,7 @@ public:
*/
template <typename Factory>
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

View File

@ -35,6 +35,7 @@ liblyxsupport_a_SOURCES = \
FileMonitor.h \
FileMonitor.cpp \
RandomAccessList.h \
any.h \
bind.h \
Cache.h \
Changer.h \

23
src/support/any.h Normal file
View File

@ -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 <any>
namespace lyx { using std::any; }
#else
#include <boost/any.hpp>
namespace lyx { using boost::any; }
#endif
#endif // LYX_ANY_H