f5256e16df
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@103516 91177308-0d34-0410-b5e6-96231b3b80d8
53 lines
1.2 KiB
C++
53 lines
1.2 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> const Facet& use_facet(const locale& loc);
|
|
|
|
#include <locale>
|
|
#include <cassert>
|
|
|
|
int facet_count = 0;
|
|
|
|
struct my_facet
|
|
: public std::locale::facet
|
|
{
|
|
static std::locale::id id;
|
|
|
|
bool im_alive;
|
|
|
|
my_facet() : im_alive(true) {++facet_count;}
|
|
~my_facet() {im_alive = false; --facet_count;}
|
|
};
|
|
|
|
std::locale::id my_facet::id;
|
|
|
|
int main()
|
|
{
|
|
try
|
|
{
|
|
const my_facet& f = std::use_facet<my_facet>(std::locale());
|
|
assert(false);
|
|
}
|
|
catch (std::bad_cast&)
|
|
{
|
|
}
|
|
const my_facet* fp = 0;
|
|
{
|
|
std::locale loc(std::locale(), new my_facet);
|
|
const my_facet& f = std::use_facet<my_facet>(loc);
|
|
assert(f.im_alive);
|
|
fp = &f;
|
|
assert(fp->im_alive);
|
|
assert(facet_count == 1);
|
|
}
|
|
assert(facet_count == 0);
|
|
}
|