Files
boost_typeof/test/main.cpp
T

178 lines
5.7 KiB
C++
Raw Normal View History

2004-11-17 19:51:22 +00:00
// Copyright (C) 2004 Arkadiy Vertleyb
// Use, modification and distribution is subject to the Boost Software
// License, Version 1.0. (http://www.boost.org/LICENSE_1_0.txt)
#pragma message("including typeof.hpp...")
#include <boost/typeof/typeof.hpp>
#pragma message("done")
#include <boost/detail/workaround.hpp>
2004-11-17 19:51:22 +00:00
#include <boost/type_traits/is_same.hpp>
#include <boost/static_assert.hpp>
#include <boost/noncopyable.hpp>
#include <cassert>
#include <iostream>
#include "mpl/register.hpp"
2005-01-03 02:54:20 +00:00
#include <boost/typeof/std/string.hpp>
#include <boost/typeof/std/deque.hpp>
#include <boost/typeof/std/list.hpp>
#include <boost/typeof/std/queue.hpp>
#include <boost/typeof/std/stack.hpp>
#include <boost/typeof/std/vector.hpp>
#include <boost/typeof/std/map.hpp>
#include <boost/typeof/std/set.hpp>
#include <boost/typeof/std/bitset.hpp>
2004-11-17 19:51:22 +00:00
#include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP()
using namespace std;
2005-01-03 02:54:20 +00:00
using namespace boost;
template<class T>
mpl::vector1<T> typeof_test_helper();
2004-11-17 19:51:22 +00:00
template<class T>
struct typeof_test
{
enum {value = boost::is_same<
2005-01-03 02:54:20 +00:00
BOOST_TYPEOF_TPL(typeof_test_helper<T>()),
mpl::vector1<T>
>::value
};
2004-11-17 19:51:22 +00:00
};
#pragma message("started")
struct x
{};
2004-12-16 03:46:58 +00:00
BOOST_TYPEOF_REGISTER_TYPE(x)
2004-11-17 19:51:22 +00:00
template<class T, char c, unsigned short us,
int i, unsigned long ul, bool b1, bool b2, unsigned u> struct with_integrals
{};
BOOST_TYPEOF_REGISTER_TEMPLATE_X(with_integrals,
(class)
(char)
(unsigned short)
(int)
(unsigned long)
(bool)
(bool)
(unsigned)
2004-12-16 03:46:58 +00:00
)
2004-11-17 19:51:22 +00:00
#pragma message("integral...")
BOOST_STATIC_ASSERT((typeof_test<with_integrals<int, 5, 4, 3, 2, true, false, 5> >::value));
BOOST_STATIC_ASSERT((typeof_test<with_integrals<int, 1, 1, 0, ULONG_MAX, false, true, 0> >::value));
2005-01-03 02:54:20 +00:00
#pragma message("namespace-level function pointers...")
2004-11-17 19:51:22 +00:00
BOOST_STATIC_ASSERT(typeof_test<double(*)()>::value);
BOOST_STATIC_ASSERT(typeof_test<double(*)(int, double, short, char*, bool, char, float, long, unsigned short)>::value);
BOOST_STATIC_ASSERT(typeof_test<void(*)()>::value);
BOOST_STATIC_ASSERT(typeof_test<void(*)(int, double, short, char*, bool, char, float, long, unsigned short)>::value);
2004-12-12 15:56:11 +00:00
#pragma message("function references...")
2005-01-03 02:54:20 +00:00
BOOST_STATIC_ASSERT(typeof_test<void(&)()>::value);
BOOST_STATIC_ASSERT(typeof_test<int(&)(int, short)>::value);
#ifdef BOOST_TYPEOF_COMPLIANT
# pragma message("function values...")
BOOST_STATIC_ASSERT(typeof_test<void()>::value);
BOOST_STATIC_ASSERT(typeof_test<double(bool)>::value);
#endif//BOOST_TYPEOF_COMPLIANT
2004-12-12 15:56:11 +00:00
2004-11-17 19:51:22 +00:00
#pragma message("member functions...")
BOOST_STATIC_ASSERT(typeof_test<double(x::*)()>::value);
BOOST_STATIC_ASSERT(typeof_test<double(x::*)(int, double, short, char*, bool, char, float, long, unsigned short)>::value);
BOOST_STATIC_ASSERT(typeof_test<void(x::*)()>::value);
BOOST_STATIC_ASSERT(typeof_test<void(x::*)(int, double, short, char*, bool, char, float, long, unsigned short)>::value);
BOOST_STATIC_ASSERT(typeof_test<double(x::*)()const>::value);
BOOST_STATIC_ASSERT(typeof_test<double(x::*)()volatile>::value);
BOOST_STATIC_ASSERT(typeof_test<double(x::*)()volatile const>::value);
#pragma message("data members...")
BOOST_STATIC_ASSERT(typeof_test<double x::*>::value);
#pragma message("modifiers...")
BOOST_STATIC_ASSERT((typeof_test<boost::mpl::vector3<const int* const, const int[20], const int&>*>::value));
#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
2004-11-17 19:51:22 +00:00
BOOST_STATIC_ASSERT((typeof_test<boost::mpl::vector2<const int* const, const int&>&>::value));
#endif
2004-11-17 19:51:22 +00:00
BOOST_STATIC_ASSERT((typeof_test<boost::mpl::vector1<int[5]> >::value));
BOOST_STATIC_ASSERT((typeof_test<boost::mpl::vector1<const int[5]> >::value));
#pragma message("Lvalue test...")
void lvalue_typeof_test()
{
int n;
const int cn = 0;
int& rn = n;
const int& rcn = cn;
int f();
//const int cf();
int& rf();
const int& rcf();
BOOST_STATIC_ASSERT((boost::is_same<BOOST_LVALUE_TYPEOF(n), int&>::value));
BOOST_STATIC_ASSERT((boost::is_same<BOOST_LVALUE_TYPEOF(cn), const int&>::value));
BOOST_STATIC_ASSERT((boost::is_same<BOOST_LVALUE_TYPEOF(rn), int&>::value));
BOOST_STATIC_ASSERT((boost::is_same<BOOST_LVALUE_TYPEOF(rcn), const int&>::value));
BOOST_STATIC_ASSERT((boost::is_same<BOOST_LVALUE_TYPEOF(f()), int>::value));
BOOST_STATIC_ASSERT((boost::is_same<BOOST_LVALUE_TYPEOF(rf()), int&>::value));
BOOST_STATIC_ASSERT((boost::is_same<BOOST_LVALUE_TYPEOF(rcf()), const int&>::value));
//BOOST_STATIC_ASSERT((boost::is_same<BOOST_LVALUE_TYPEOF(cf()), const int&>::value));
//BOOST_STATIC_ASSERT((boost::is_same<BOOST_LVALUE_TYPEOF(21), int>::value));
//BOOST_STATIC_ASSERT((boost::is_same<BOOST_LVALUE_TYPEOF(int(21)), int>::value));
}
#pragma message("Noncopyable...")
2004-12-16 03:46:58 +00:00
BOOST_TYPEOF_REGISTER_TYPE(boost::noncopyable)
2004-11-17 19:51:22 +00:00
2005-01-03 02:54:20 +00:00
const boost::noncopyable& noncopiable_test_helper();
2004-11-17 19:51:22 +00:00
struct noncopiable_test
{
void bar()
{
2005-01-03 02:54:20 +00:00
BOOST_AUTO(const& v, noncopiable_test_helper());
2004-12-12 15:56:11 +00:00
v; // to avoid warning
2004-11-17 19:51:22 +00:00
}
};
2005-01-03 02:54:20 +00:00
#pragma message("STL...")
BOOST_STATIC_ASSERT(typeof_test<string>::value);
BOOST_STATIC_ASSERT(typeof_test<deque<int> >::value);
BOOST_STATIC_ASSERT(typeof_test<list<int> >::value);
BOOST_STATIC_ASSERT(typeof_test<queue<int> >::value);
BOOST_STATIC_ASSERT(typeof_test<stack<int> >::value);
BOOST_STATIC_ASSERT(typeof_test<vector<int> >::value);
BOOST_STATIC_ASSERT((typeof_test<map<int, int> >::value));
BOOST_STATIC_ASSERT((typeof_test<multimap<int, int> >::value));
BOOST_STATIC_ASSERT(typeof_test<set<int> >::value);
BOOST_STATIC_ASSERT(typeof_test<multiset<int> >::value);
BOOST_STATIC_ASSERT(typeof_test<bitset<10> >::value);
2004-11-17 19:51:22 +00:00
#pragma message("ODR...")
void odr_test()
{
void odr_test1();
void odr_test2();
odr_test1();
odr_test2();
}
#pragma message("main()...")
2004-12-15 03:24:29 +00:00
int main()
2004-11-17 19:51:22 +00:00
{
odr_test();
}
#pragma message("done!")