Skip to content

Commit aa1cb70

Browse files
committed
refs #18, fighting VS2015 sfinae issues
1 parent 15788d8 commit aa1cb70

File tree

3 files changed

+29
-24
lines changed

3 files changed

+29
-24
lines changed

examples/dir.cpp

+17-16
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
1-
#include <iostream>
2-
#include <iomanip>
31
#include <chrono>
2+
#include <iomanip>
3+
#include <iostream>
44
#include <string>
55

6-
#if defined(__cplusplus) && __cplusplus >= 201703L && defined(__has_include) && __has_include(<filesystem>)
6+
#if defined(__cplusplus) && __cplusplus >= 201703L && defined(__has_include)
7+
#if __has_include(<filesystem>)
78
#include <filesystem>
89
namespace fs = std::filesystem;
9-
#else
10+
#define GHC_USE_STD_FS
11+
#endif
12+
#endif
13+
#ifndef GHC_USE_STD_FS
1014
#include <ghc/filesystem.hpp>
1115
namespace fs = ghc::filesystem;
1216
#endif
1317

14-
template<typename TP>
18+
template <typename TP>
1519
std::time_t to_time_t(TP tp)
1620
{
1721
// Based on trick from: Nico Josuttis, C++17 - The Complete Guide
@@ -23,8 +27,8 @@ static std::string perm_to_str(fs::perms prms)
2327
{
2428
std::string result;
2529
result.reserve(9);
26-
for(int i = 0; i < 9; ++i) {
27-
result = ((static_cast<int>(prms) & (1<<i)) ? "xwrxwrxwr"[i] : '-') + result;
30+
for (int i = 0; i < 9; ++i) {
31+
result = ((static_cast<int>(prms) & (1 << i)) ? "xwrxwrxwr"[i] : '-') + result;
2832
}
2933
return result;
3034
}
@@ -33,27 +37,24 @@ int main(int argc, char* argv[])
3337
{
3438
#ifdef GHC_FILESYSTEM_VERSION
3539
fs::u8arguments u8guard(argc, argv);
36-
if(!u8guard.valid()) {
40+
if (!u8guard.valid()) {
3741
std::cerr << "Invalid character encoding, UTF-8 based encoding needed." << std::endl;
3842
std::exit(EXIT_FAILURE);
3943
}
4044
#endif
41-
if(argc > 2) {
45+
if (argc > 2) {
4246
std::cerr << "USAGE: dir <path>" << std::endl;
4347
exit(1);
4448
}
4549
fs::path dir{"."};
46-
if(argc == 2) {
50+
if (argc == 2) {
4751
dir = fs::u8path(argv[1]);
4852
}
49-
for(auto de : fs::directory_iterator(dir)) {
53+
for (auto de : fs::directory_iterator(dir)) {
5054
auto ft = to_time_t(de.last_write_time());
5155
auto ftm = *std::localtime(&ft);
52-
std::cout << (de.is_directory() ? "d" : "-") << perm_to_str(de.symlink_status().permissions()) << " "
53-
<< std::setw(8) << (de.is_directory() ? "-" : std::to_string(de.file_size())) << " "
54-
<< std::put_time(&ftm, "%Y-%m-%d %H:%M:%S") << " "
55-
<< de.path().filename().string()
56-
<< std::endl;
56+
std::cout << (de.is_directory() ? "d" : "-") << perm_to_str(de.symlink_status().permissions()) << " " << std::setw(8) << (de.is_directory() ? "-" : std::to_string(de.file_size())) << " " << std::put_time(&ftm, "%Y-%m-%d %H:%M:%S") << " "
57+
<< de.path().filename().string() << std::endl;
5758
}
5859
return 0;
5960
}

examples/du.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22
#include <iomanip>
33
#include <chrono>
44

5-
#if defined(__cplusplus) && __cplusplus >= 201703L && defined(__has_include) && __has_include(<filesystem>)
5+
#if defined(__cplusplus) && __cplusplus >= 201703L && defined(__has_include)
6+
#if __has_include(<filesystem>)
67
#include <filesystem>
78
namespace fs = std::filesystem;
8-
#else
9+
#define GHC_USE_STD_FS
10+
#endif
11+
#endif
12+
#ifndef GHC_USE_STD_FS
913
#include <ghc/filesystem.hpp>
1014
namespace fs = ghc::filesystem;
1115
#endif

include/ghc/filesystem.hpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -1296,13 +1296,13 @@ inline StringType fromUtf8(const std::string& utf8String, const typename StringT
12961296
return result;
12971297
}
12981298

1299-
template <typename charT, typename traits, typename Alloc, typename std::enable_if<(sizeof(charT) == 1)>::type* = nullptr>
1299+
template <typename charT, typename traits, typename Alloc, typename std::enable_if<(sizeof(charT) == 1), int>::type size = 1>
13001300
inline std::string toUtf8(const std::basic_string<charT, traits, Alloc>& unicodeString)
13011301
{
13021302
return std::string(unicodeString.begin(), unicodeString.end());
13031303
}
13041304

1305-
template <typename charT, typename traits, typename Alloc, typename std::enable_if<(sizeof(charT) == 2)>::type* = nullptr>
1305+
template <typename charT, typename traits, typename Alloc, typename std::enable_if<(sizeof(charT) == 2), int>::type size = 2>
13061306
inline std::string toUtf8(const std::basic_string<charT, traits, Alloc>& unicodeString)
13071307
{
13081308
std::string result;
@@ -1324,7 +1324,7 @@ inline std::string toUtf8(const std::basic_string<charT, traits, Alloc>& unicode
13241324
return result;
13251325
}
13261326

1327-
template <typename charT, typename traits, typename Alloc, typename std::enable_if<(sizeof(charT) == 4)>::type* = nullptr>
1327+
template <typename charT, typename traits, typename Alloc, typename std::enable_if<(sizeof(charT) == 4), int>::type size = 4>
13281328
inline std::string toUtf8(const std::basic_string<charT, traits, Alloc>& unicodeString)
13291329
{
13301330
std::string result;
@@ -1334,10 +1334,10 @@ inline std::string toUtf8(const std::basic_string<charT, traits, Alloc>& unicode
13341334
return result;
13351335
}
13361336

1337-
template <typename SourceType>
1338-
inline std::string toUtf8(const SourceType* unicodeString)
1337+
template <typename charT>
1338+
inline std::string toUtf8(const charT* unicodeString)
13391339
{
1340-
return toUtf8(std::basic_string<SourceType, std::char_traits<SourceType>>(unicodeString));
1340+
return toUtf8(std::basic_string<charT, std::char_traits<charT>>(unicodeString));
13411341
}
13421342

13431343
} // namespace detail

0 commit comments

Comments
 (0)