assign_F_alloc.pass.cpp revision 1b92188a82b01e76ac6e8ad5f997293c2a078adc
1a5728872c7702ddd09537c95bc3cbd20e1f2fb09Daniel Dunbar//===----------------------------------------------------------------------===// 28e8fb3be5bd78f0564444eca02b404566a5f3b5dAndy Gibbs// 3d0b7839f8a82141193e578d9eb1bc168dda9c8dfJohn McCall// The LLVM Compiler Infrastructure 4d0b7839f8a82141193e578d9eb1bc168dda9c8dfJohn McCall// 5d0b7839f8a82141193e578d9eb1bc168dda9c8dfJohn McCall// This file is dual licensed under the MIT and the University of Illinois Open 6d0b7839f8a82141193e578d9eb1bc168dda9c8dfJohn McCall// Source Licenses. See LICENSE.TXT for details. 7d0b7839f8a82141193e578d9eb1bc168dda9c8dfJohn McCall// 8d0b7839f8a82141193e578d9eb1bc168dda9c8dfJohn McCall//===----------------------------------------------------------------------===// 9d0b7839f8a82141193e578d9eb1bc168dda9c8dfJohn McCall 10d0b7839f8a82141193e578d9eb1bc168dda9c8dfJohn McCall// <functional> 11d0b7839f8a82141193e578d9eb1bc168dda9c8dfJohn McCall 12d0b7839f8a82141193e578d9eb1bc168dda9c8dfJohn McCall// class function<R(ArgTypes...)> 13d0b7839f8a82141193e578d9eb1bc168dda9c8dfJohn McCall 14d0b7839f8a82141193e578d9eb1bc168dda9c8dfJohn McCall// template<class F, class A> void assign(F&&, const A&); 15d0b7839f8a82141193e578d9eb1bc168dda9c8dfJohn McCall 16d0b7839f8a82141193e578d9eb1bc168dda9c8dfJohn McCall#include <functional> 17d0b7839f8a82141193e578d9eb1bc168dda9c8dfJohn McCall#include <cassert> 18d0b7839f8a82141193e578d9eb1bc168dda9c8dfJohn McCall 19d0b7839f8a82141193e578d9eb1bc168dda9c8dfJohn McCall#include "test_allocator.h" 20d0b7839f8a82141193e578d9eb1bc168dda9c8dfJohn McCall 21d0b7839f8a82141193e578d9eb1bc168dda9c8dfJohn McCallclass A 22d0b7839f8a82141193e578d9eb1bc168dda9c8dfJohn McCall{ 231fe6b919f70bed58bd8bd43de1a79530b0d55a53Douglas Gregor int data_[10]; 241fe6b919f70bed58bd8bd43de1a79530b0d55a53Douglas Gregorpublic: 251fe6b919f70bed58bd8bd43de1a79530b0d55a53Douglas Gregor static int count; 261fe6b919f70bed58bd8bd43de1a79530b0d55a53Douglas Gregor 271fe6b919f70bed58bd8bd43de1a79530b0d55a53Douglas Gregor A() 281fe6b919f70bed58bd8bd43de1a79530b0d55a53Douglas Gregor { 291fe6b919f70bed58bd8bd43de1a79530b0d55a53Douglas Gregor ++count; 301fe6b919f70bed58bd8bd43de1a79530b0d55a53Douglas Gregor for (int i = 0; i < 10; ++i) 311fe6b919f70bed58bd8bd43de1a79530b0d55a53Douglas Gregor data_[i] = i; 321fe6b919f70bed58bd8bd43de1a79530b0d55a53Douglas Gregor } 331fe6b919f70bed58bd8bd43de1a79530b0d55a53Douglas Gregor 341fe6b919f70bed58bd8bd43de1a79530b0d55a53Douglas Gregor A(const A&) {++count;} 351fe6b919f70bed58bd8bd43de1a79530b0d55a53Douglas Gregor 361fe6b919f70bed58bd8bd43de1a79530b0d55a53Douglas Gregor ~A() {--count;} 371fe6b919f70bed58bd8bd43de1a79530b0d55a53Douglas Gregor 38 int operator()(int i) const 39 { 40 for (int j = 0; j < 10; ++j) 41 i += data_[j]; 42 return i; 43 } 44 45 int foo(int) const {return 1;} 46}; 47 48int A::count = 0; 49 50int main() 51{ 52 { 53 std::function<int(int)> f; 54 f.assign(A(), test_allocator<A>()); 55 assert(A::count == 1); 56 assert(f.target<A>()); 57 assert(f.target<int(*)(int)>() == 0); 58 } 59 assert(A::count == 0); 60} 61