f5256e16df
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@103516 91177308-0d34-0410-b5e6-96231b3b80d8
108 lines
3.1 KiB
C++
108 lines
3.1 KiB
C++
//===----------------------------------------------------------------------===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// <locale>
|
|
|
|
// template <class Facet> locale combine(const locale& other) const;
|
|
|
|
#include <locale>
|
|
#include <new>
|
|
#include <cassert>
|
|
|
|
int new_called = 0;
|
|
|
|
void* operator new(std::size_t s) throw(std::bad_alloc)
|
|
{
|
|
++new_called;
|
|
return std::malloc(s);
|
|
}
|
|
|
|
void operator delete(void* p) throw()
|
|
{
|
|
--new_called;
|
|
std::free(p);
|
|
}
|
|
|
|
void check(const std::locale& loc)
|
|
{
|
|
assert(std::has_facet<std::collate<char> >(loc));
|
|
assert(std::has_facet<std::collate<wchar_t> >(loc));
|
|
|
|
assert(std::has_facet<std::ctype<char> >(loc));
|
|
assert(std::has_facet<std::ctype<wchar_t> >(loc));
|
|
assert((std::has_facet<std::codecvt<char, char, std::mbstate_t> >(loc)));
|
|
assert((std::has_facet<std::codecvt<char16_t, char, std::mbstate_t> >(loc)));
|
|
assert((std::has_facet<std::codecvt<char32_t, char, std::mbstate_t> >(loc)));
|
|
assert((std::has_facet<std::codecvt<wchar_t, char, std::mbstate_t> >(loc)));
|
|
|
|
assert((std::has_facet<std::moneypunct<char> >(loc)));
|
|
assert((std::has_facet<std::moneypunct<wchar_t> >(loc)));
|
|
assert((std::has_facet<std::money_get<char> >(loc)));
|
|
assert((std::has_facet<std::money_get<wchar_t> >(loc)));
|
|
assert((std::has_facet<std::money_put<char> >(loc)));
|
|
assert((std::has_facet<std::money_put<wchar_t> >(loc)));
|
|
|
|
assert((std::has_facet<std::numpunct<char> >(loc)));
|
|
assert((std::has_facet<std::numpunct<wchar_t> >(loc)));
|
|
assert((std::has_facet<std::num_get<char> >(loc)));
|
|
assert((std::has_facet<std::num_get<wchar_t> >(loc)));
|
|
assert((std::has_facet<std::num_put<char> >(loc)));
|
|
assert((std::has_facet<std::num_put<wchar_t> >(loc)));
|
|
|
|
assert((std::has_facet<std::time_get<char> >(loc)));
|
|
assert((std::has_facet<std::time_get<wchar_t> >(loc)));
|
|
assert((std::has_facet<std::time_put<char> >(loc)));
|
|
assert((std::has_facet<std::time_put<wchar_t> >(loc)));
|
|
|
|
assert((std::has_facet<std::messages<char> >(loc)));
|
|
assert((std::has_facet<std::messages<wchar_t> >(loc)));
|
|
}
|
|
|
|
struct my_facet
|
|
: public std::locale::facet
|
|
{
|
|
int test() const {return 5;}
|
|
|
|
static std::locale::id id;
|
|
};
|
|
|
|
std::locale::id my_facet::id;
|
|
|
|
int main()
|
|
{
|
|
{
|
|
{
|
|
std::locale loc;
|
|
std::locale loc2(loc, new my_facet);
|
|
std::locale loc3 = loc.combine<my_facet>(loc2);
|
|
check(loc3);
|
|
assert(loc3.name() == "*");
|
|
assert((std::has_facet<my_facet>(loc3)));
|
|
const my_facet& f = std::use_facet<my_facet>(loc3);
|
|
assert(f.test() == 5);
|
|
}
|
|
assert(new_called == 0);
|
|
}
|
|
{
|
|
{
|
|
std::locale loc;
|
|
std::locale loc2;
|
|
try
|
|
{
|
|
std::locale loc3 = loc.combine<my_facet>(loc2);
|
|
assert(false);
|
|
}
|
|
catch (std::runtime_error&)
|
|
{
|
|
}
|
|
}
|
|
assert(new_called == 0);
|
|
}
|
|
}
|