1234567891011121314151617181920212223242526272829303132 |
- #ifndef NANXING_TEST_PRINT_
- #define NANXING_TEST_PRINT_
- #include<fstream>
- #include<string>
- #include<iostream>
- #include<type_traits>
- namespace nanxing_test{
- template<typename K>
- using void_t=void;
- template<typename K,typename V=void>
- struct ofstream_admit:std::false_type{};
- template<typename K>
- struct ofstream_admit<K,void_t<decltype(std::declval<std::ofstream&>()<<std::declval<K>())>>:std::true_type{};
- template<typename T>
- static void inseat_result_to_txt(T result)
- {
- static_assert(ofstream_admit<T>::value,"The type of T cannot print by ofstream");
- std::ofstream output("../../test_result.txt",std::ios_base::app);
- if(!output.is_open())
- {
- std::cerr << "Failed to open the file." << std::endl;
- }
- output<<result<<std::endl;
- output.close();
- }
- }
- #endif
|