mirror of
				https://github.com/SoftFever/OrcaSlicer.git
				synced 2025-10-30 20:21:12 -06:00 
			
		
		
		
	Merge branch 'tm_cpp17_test'
This commit is contained in:
		
						commit
						b10ee7217c
					
				
					 3 changed files with 90 additions and 0 deletions
				
			
		|  | @ -27,4 +27,5 @@ add_subdirectory(libslic3r) | ||||||
| add_subdirectory(timeutils) | add_subdirectory(timeutils) | ||||||
| add_subdirectory(fff_print) | add_subdirectory(fff_print) | ||||||
| add_subdirectory(sla_print) | add_subdirectory(sla_print) | ||||||
|  | add_subdirectory(cpp17 EXCLUDE_FROM_ALL)    # does not have to be built all the time | ||||||
| # add_subdirectory(example) | # add_subdirectory(example) | ||||||
|  |  | ||||||
							
								
								
									
										9
									
								
								tests/cpp17/CMakeLists.txt
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								tests/cpp17/CMakeLists.txt
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,9 @@ | ||||||
|  | cmake_minimum_required(VERSION 3.1) | ||||||
|  | 
 | ||||||
|  | project(Cpp17Test) | ||||||
|  | 
 | ||||||
|  | set(CMAKE_CXX_STANDARD 17) | ||||||
|  | set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||||||
|  | 
 | ||||||
|  | add_executable(cpp17test main.cpp) | ||||||
|  | 
 | ||||||
							
								
								
									
										80
									
								
								tests/cpp17/main.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										80
									
								
								tests/cpp17/main.cpp
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,80 @@ | ||||||
|  | #include <cstdlib> | ||||||
|  | #include <iostream> | ||||||
|  | #include <tuple> | ||||||
|  | #include <string> | ||||||
|  | 
 | ||||||
|  | // Test new headers in cpp17
 | ||||||
|  | #include <variant> | ||||||
|  | #include <optional> | ||||||
|  | #include <any> | ||||||
|  | #include <string_view> | ||||||
|  | 
 | ||||||
|  | // Test for nested namespace definition
 | ||||||
|  | namespace PrusaSlicer::Cpp17 { | ||||||
|  | 
 | ||||||
|  | template<class T> class Foo | ||||||
|  | { | ||||||
|  |     T m_arg; | ||||||
|  | public: | ||||||
|  |      | ||||||
|  |     explicit Foo(T &&arg): m_arg{arg} {} | ||||||
|  | }; | ||||||
|  | 
 | ||||||
|  | } // namespace PrusaSlicer::Cpp17
 | ||||||
|  | 
 | ||||||
|  | template<class T> std::string get_type(const T &v); | ||||||
|  | 
 | ||||||
|  | template<> std::string get_type(const int &) { return "int"; } | ||||||
|  | template<> std::string get_type(const double &) { return "double"; } | ||||||
|  | template<> std::string get_type(const float &) { return "double"; } | ||||||
|  | 
 | ||||||
|  | int main() | ||||||
|  | { | ||||||
|  |     // /////////////////////////////////////////////////////////////////////////
 | ||||||
|  |     // Template argument deduction for class templates
 | ||||||
|  |     // /////////////////////////////////////////////////////////////////////////
 | ||||||
|  |      | ||||||
|  |     auto foo = PrusaSlicer::Cpp17::Foo{1.f}; | ||||||
|  |      | ||||||
|  |     // /////////////////////////////////////////////////////////////////////////
 | ||||||
|  |     // Structured bindings:
 | ||||||
|  |     // /////////////////////////////////////////////////////////////////////////
 | ||||||
|  |      | ||||||
|  |     auto my_tuple = std::make_tuple(0.2, 10); | ||||||
|  |      | ||||||
|  |     auto [a, b] = my_tuple; | ||||||
|  |      | ||||||
|  |     std::cout << "a is " << get_type(a) << std::endl; | ||||||
|  |     std::cout << "b is " << get_type(b) << std::endl; | ||||||
|  |      | ||||||
|  |     // /////////////////////////////////////////////////////////////////////////
 | ||||||
|  |     // Test for std::apply()
 | ||||||
|  |     // /////////////////////////////////////////////////////////////////////////
 | ||||||
|  |      | ||||||
|  |     auto fun = [] (auto a, auto b) { | ||||||
|  |         std::cout << "a (" << get_type(a) << ") = " << a << std::endl; | ||||||
|  |         std::cout << "b (" << get_type(b) << ") = " << b << std::endl; | ||||||
|  |     }; | ||||||
|  |      | ||||||
|  |     std::apply(fun, my_tuple); | ||||||
|  |      | ||||||
|  |     // /////////////////////////////////////////////////////////////////////////
 | ||||||
|  |     // constexpr lambda and if
 | ||||||
|  |     // /////////////////////////////////////////////////////////////////////////
 | ||||||
|  |      | ||||||
|  |     auto isIntegral = [](auto v) constexpr -> bool { | ||||||
|  |         if constexpr (std::is_integral_v<decltype(v)>) { | ||||||
|  |             return true; | ||||||
|  |         } else { | ||||||
|  |             return false; | ||||||
|  |         } | ||||||
|  |     }; | ||||||
|  |      | ||||||
|  |     static_assert (isIntegral(10), "" ); | ||||||
|  |     // would fail to compile: static_assert (isIntegral(10.0), "" );
 | ||||||
|  |      | ||||||
|  |     std::cout << "Integer is integral: " << isIntegral(0) << std::endl; | ||||||
|  |     std::cout << "Floating point is not integral: " << isIntegral(0.0) << std::endl; | ||||||
|  |      | ||||||
|  |     return EXIT_SUCCESS; | ||||||
|  | } | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 tamasmeszaros
						tamasmeszaros