1 // Copyright 2016 Klemens Morgenstern
2 //
3 // Distributed under the Boost Software License, Version 1.0.
4 // (See accompanying file LICENSE_1_0.txt
5 // or copy at http://www.boost.org/LICENSE_1_0.txt)
6
7 // For more information, see http://www.boost.org
8
9 #include <boost/config.hpp>
10
11 #if (__cplusplus >= 201402L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201402L)
12
13 #include "../example/b2_workarounds.hpp"
14
15 #include <boost/dll/smart_library.hpp>
16 #include <boost/dll/import_mangled.hpp>
17
18 #include <boost/core/lightweight_test.hpp>
19 #include <boost/filesystem.hpp>
20 #include <boost/variant.hpp>
21 #include <boost/function.hpp>
22
23 #include <iostream>
24
25 struct override_class
26 {
27 int arr[32];
28 };
29
30
main(int argc,char * argv[])31 int main(int argc, char* argv[])
32 {
33 using namespace boost::dll;
34 using namespace boost::dll::experimental;
35 boost::dll::fs::path pt = b2_workarounds::first_lib_from_argv(argc, argv);
36
37 BOOST_TEST(!pt.empty());
38 std::cout << "Library: " << pt << std::endl;
39
40 smart_library sm(pt);
41
42 auto sp_variable = import_mangled<double>(sm, "some_space::variable");
43
44 auto unscoped_var = import_mangled<int>(sm, "unscoped_var");
45
46
47 auto ovl = import_mangled<void(int), void(double)>(sm, "overloaded");
48
49 ovl(12);
50 BOOST_TEST(*unscoped_var == 12);
51 ovl(5.0);
52 BOOST_TEST(*sp_variable == 5.0);
53
54 boost::function<void(int)> f_test = ovl;//test if it binds
55 f_test(-2);
56 BOOST_TEST(*unscoped_var == -2);
57
58 sm.add_type_alias<override_class>("some_space::some_class");
59
60 auto func = import_mangled<
61 override_class, double(double, double), int(int, int),
62 volatile override_class, int(int, int),
63 const volatile override_class, double(double, double)>(sm, "func");
64
65 override_class override_class_varible{};
66
67 override_class *ov = &override_class_varible;
68 volatile override_class *ovv = ov;
69 const volatile override_class *ovcv = ov;
70
71 BOOST_TEST(func(ov, 3.,2.) == 6.);
72 BOOST_TEST(func(ov, 1,2 ) == 3 );
73 BOOST_TEST(func(ovv, 10,2) == 8 );
74 BOOST_TEST(func(ovcv, 9,2) == 4.5 );
75
76 return boost::report_errors();
77 }
78
79 #else
main()80 int main() {return 0;}
81 #endif
82