]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/dll/test/template_method_linux_test.cpp
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / boost / libs / dll / test / template_method_linux_test.cpp
1 // Copyright 2019 Ramil Gauss.
2 // Copyright 2019 Antony Polukhin.
3 //
4 // Distributed under the Boost Software License, Version 1.0.
5 // (See accompanying file LICENSE_1_0.txt
6 // or copy at http://www.boost.org/LICENSE_1_0.txt)
7
8 #include <boost/predef.h>
9 #if (__cplusplus >= 201402L) || (BOOST_COMP_MSVC >= BOOST_VERSION_NUMBER(14,0,0))
10
11 #include <boost/dll/smart_library.hpp>
12 #include <boost/dll/import_mangled.hpp>
13 #include <boost/dll/import_class.hpp>
14
15 #include <iostream>
16 #include <string>
17
18 #include "../example/b2_workarounds.hpp"
19 #include <boost/core/lightweight_test.hpp>
20
21
22 namespace space {
23 class BOOST_SYMBOL_EXPORT my_plugin {
24 public:
25 template <typename Arg>
26 BOOST_SYMBOL_EXPORT int Func(); // defined in cpp_test_library.cpp
27 };
28 }
29
30 int main(int argc, char** argv) {
31 unsigned matches_found = 0;
32 boost::dll::fs::path lib_path = b2_workarounds::first_lib_from_argv(argc, argv);
33 boost::dll::experimental::smart_library lib(lib_path);
34
35 auto storage = lib.symbol_storage().get_storage();
36 for (auto& s : storage) {
37 auto& demangled = s.demangled;
38 BOOST_TEST(demangled.data());
39
40 auto beginFound = demangled.find("Func<");
41 if (beginFound == std::string::npos)
42 continue;
43
44 auto endFound = demangled.find("(");
45 if (endFound == std::string::npos)
46 continue;
47
48 // Usually "Func<space::my_plugin>" on Linux, "Func<class space::my_plugin>" on Windows.
49 auto funcName = demangled.substr(beginFound, endFound - beginFound);
50 std::cout << "Function name: " << funcName.data() << std::endl;
51 auto typeIndexFunc = boost::dll::experimental::import_mangled<space::my_plugin, int()>(lib, funcName);
52
53 space::my_plugin cl;
54 BOOST_TEST_EQ(typeIndexFunc(&cl), 42);
55
56 ++matches_found;
57 break;
58 }
59 BOOST_TEST_EQ(matches_found, 1);
60
61 return boost::report_errors();
62 }
63
64
65 #else
66 int main() {}
67 #endif