emplace_front.pass.cpp revision 4e42dc97f3cf3e63ef3e6a23cada1970259eb7ea
1//===----------------------------------------------------------------------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is dual licensed under the MIT and the University of Illinois Open 6// Source Licenses. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9 10// UNSUPPORTED: c++98, c++03 11 12// <forward_list> 13 14// template <class... Args> reference emplace_front(Args&&... args); 15// return type is 'reference' in C++17; 'void' before 16 17#include <forward_list> 18#include <cassert> 19 20#include "test_macros.h" 21 22#include "../../../Emplaceable.h" 23#include "min_allocator.h" 24 25int main() 26{ 27 { 28 typedef Emplaceable T; 29 typedef std::forward_list<T> C; 30 C c; 31#if TEST_STD_VER > 14 32 T& r1 = c.emplace_front(); 33 assert(c.front() == Emplaceable()); 34 assert(&r1 == &c.front()); 35 assert(distance(c.begin(), c.end()) == 1); 36 T& r2 = c.emplace_front(1, 2.5); 37 assert(c.front() == Emplaceable(1, 2.5)); 38 assert(&r2 == &c.front()); 39#else 40 c.emplace_front(); 41 assert(c.front() == Emplaceable()); 42 assert(distance(c.begin(), c.end()) == 1); 43 c.emplace_front(1, 2.5); 44 assert(c.front() == Emplaceable(1, 2.5)); 45#endif 46 assert(*next(c.begin()) == Emplaceable()); 47 assert(distance(c.begin(), c.end()) == 2); 48 } 49 { 50 typedef Emplaceable T; 51 typedef std::forward_list<T, min_allocator<T>> C; 52 C c; 53#if TEST_STD_VER > 14 54 T& r1 = c.emplace_front(); 55 assert(c.front() == Emplaceable()); 56 assert(&r1 == &c.front()); 57 assert(distance(c.begin(), c.end()) == 1); 58 T& r2 = c.emplace_front(1, 2.5); 59 assert(c.front() == Emplaceable(1, 2.5)); 60 assert(&r2 == &c.front()); 61#else 62 c.emplace_front(); 63 assert(c.front() == Emplaceable()); 64 assert(distance(c.begin(), c.end()) == 1); 65 c.emplace_front(1, 2.5); 66 assert(c.front() == Emplaceable(1, 2.5)); 67#endif 68 assert(*next(c.begin()) == Emplaceable()); 69 assert(distance(c.begin(), c.end()) == 2); 70 } 71} 72