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 // <experimental/filesystem> 13 14 // class directory_entry 15 16 // directory_entry() noexcept = default; 17 // directory_entry(const directory_entry&) = default; 18 // directory_entry(directory_entry&&) noexcept = default; 19 // explicit directory_entry(const path); 20 21 #include <experimental/filesystem> 22 #include <type_traits> 23 #include <cassert> 24 25 namespace fs = std::experimental::filesystem; 26 27 void test_default_ctor() 28 { 29 using namespace fs; 30 // Default 31 { 32 static_assert(std::is_nothrow_default_constructible<directory_entry>::value, 33 "directory_entry must have a nothrow default constructor"); 34 directory_entry e; 35 assert(e.path() == path()); 36 } 37 } 38 39 40 void test_copy_ctor() 41 { 42 using namespace fs; 43 // Copy 44 { 45 static_assert(std::is_copy_constructible<directory_entry>::value, 46 "directory_entry must be copy constructible"); 47 static_assert(!std::is_nothrow_copy_constructible<directory_entry>::value, 48 "directory_entry's copy constructor cannot be noexcept"); 49 const path p("foo/bar/baz"); 50 const directory_entry e(p); 51 assert(e.path() == p); 52 directory_entry e2(e); 53 assert(e.path() == p); 54 assert(e2.path() == p); 55 } 56 57 } 58 59 void test_move_ctor() 60 { 61 using namespace fs; 62 // Move 63 { 64 static_assert(std::is_nothrow_move_constructible<directory_entry>::value, 65 "directory_entry must be nothrow move constructible"); 66 const path p("foo/bar/baz"); 67 directory_entry e(p); 68 assert(e.path() == p); 69 directory_entry e2(std::move(e)); 70 assert(e2.path() == p); 71 assert(e.path() != p); // Testing moved from state. 72 } 73 } 74 75 void test_path_ctor() { 76 using namespace fs; 77 { 78 static_assert(std::is_constructible<directory_entry, const path&>::value, 79 "directory_entry must be constructible from path"); 80 static_assert(!std::is_nothrow_constructible<directory_entry, const path&>::value, 81 "directory_entry constructor should not be noexcept"); 82 static_assert(!std::is_convertible<path const&, directory_entry>::value, 83 "directory_entry constructor should be explicit"); 84 } 85 { 86 const path p("foo/bar/baz"); 87 const directory_entry e(p); 88 assert(p == e.path()); 89 } 90 } 91 92 int main() { 93 test_default_ctor(); 94 test_copy_ctor(); 95 test_move_ctor(); 96 test_path_ctor(); 97 } 98