summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/any/test/any_test.cpp
blob: d722916de6627039788eb84174a84cd9e6a5ae76 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright Kevlin Henney, 2000, 2001. All rights reserved.
// Copyright Antony Polukhin, 2013-2022.
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

// what:  unit tests for variant type boost::any
// who:   contributed by Kevlin Henney
// when:  July 2001, 2013, 2014
// where: tested with BCC 5.5, MSVC 6.0, and g++ 2.95

#include <boost/any.hpp>

#include "basic_test.hpp"

static const std::string& returning_string1()
{
    static const std::string ret("foo");
    return ret;
}

static std::string returning_string2()
{
    static const std::string ret("foo");
    return ret;
}

static void test_with_func()
{
    std::string s;
    s = boost::any_cast<std::string>(returning_string1());
    s = boost::any_cast<const std::string&>(returning_string1());

    s = boost::any_cast<std::string>(returning_string2());
    s = boost::any_cast<const std::string&>(returning_string2());

#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
#if !defined(__INTEL_COMPILER) && !defined(__ICL) && (!defined(_MSC_VER) || _MSC_VER != 1600)
    // Intel compiler thinks that it must choose the `any_cast(const any&)` function
    // instead of the `any_cast(const any&&)`.
    // Bug was not reported because of missing premier support account + annoying
    // registrations requirements.

    // MSVC-10 had a bug:
    //
    // any.hpp(291) : error C2440: 'return' : cannot convert.
    // Conversion loses qualifiers
    // any_test.cpp(304) : see reference to function template instantiation
    //
    // This issue was fixed in MSVC-11.

    s = boost::any_cast<std::string&&>(returning_string1());
#endif

    s = boost::any_cast<std::string&&>(returning_string2());
#endif
}

int main() {
    test_with_func();

    return any_tests::basic_tests<boost::any>::run_tests();
}