std.exp.filesystem for vc2013
This commit is contained in:
parent
705fca5232
commit
d04776216b
@ -43,14 +43,19 @@
|
||||
|
||||
//C++ language
|
||||
#if defined(_MSC_VER)
|
||||
# undef STD_FILESYSTEM_NOT_SUPPORTED
|
||||
# if (_MSC_VER < 1900)
|
||||
# //About std.experimental.filesystem.
|
||||
# //Through VC2013 has provided <filesystem>, but all the names are given in namespace std. It's hard to alias these names into std::experimental,
|
||||
# //So Nana use nana.filesystem implement instead for VC2013
|
||||
#
|
||||
# //Nana defines some macros for lack of support of keywords
|
||||
# define _ALLOW_KEYWORD_MACROS
|
||||
#
|
||||
# define CXX_NO_INLINE_NAMESPACE //no support of C++11 inline namespace until Visual C++ 2015
|
||||
# define noexcept //no support of noexcept until Visual C++ 2015
|
||||
# define constexpr //no support of constexpr until Visual C++ 2015
|
||||
# else
|
||||
# undef STD_FILESYSTEM_NOT_SUPPORTED
|
||||
# endif
|
||||
#elif defined(__GNUC__)
|
||||
# if (__GNUC__ == 4 && __GNUC_MINOR__ < 6)
|
||||
|
@ -42,29 +42,32 @@ class directory_only_iterator : public std::experimental::filesystem::directory_
|
||||
{
|
||||
using DI = std::experimental::filesystem::directory_iterator;
|
||||
directory_only_iterator& find_first()
|
||||
{
|
||||
auto end = directory_only_iterator{};
|
||||
while (*this != end)
|
||||
{
|
||||
if (is_directory((**this).status()))
|
||||
return *this;
|
||||
this->DI::operator++();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
{
|
||||
auto end = directory_only_iterator{};
|
||||
while (*this != end)
|
||||
{
|
||||
if (is_directory((**this).status()))
|
||||
return *this;
|
||||
this->DI::operator++();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
public:
|
||||
template <class... Arg>
|
||||
directory_only_iterator(Arg&&... arg ): DI(std::forward<Arg>(arg)...)
|
||||
{
|
||||
find_first();
|
||||
}
|
||||
directory_only_iterator( ) {}
|
||||
directory_only_iterator(){}
|
||||
|
||||
template <class... Arg>
|
||||
directory_only_iterator(Arg&&... arg ): DI(std::forward<Arg>(arg)...)
|
||||
{
|
||||
find_first();
|
||||
}
|
||||
|
||||
directory_only_iterator& operator++()
|
||||
{
|
||||
this->DI::operator++();
|
||||
return find_first();
|
||||
}
|
||||
};
|
||||
|
||||
inline directory_only_iterator begin(directory_only_iterator iter) noexcept
|
||||
{
|
||||
return iter;
|
||||
@ -81,23 +84,25 @@ class regular_file_only_iterator : public std::experimental::filesystem::directo
|
||||
{
|
||||
using DI = std::experimental::filesystem::directory_iterator;
|
||||
regular_file_only_iterator& find_first()
|
||||
{
|
||||
while(( (*this) != DI{}) && !is_regular_file((**this).status()))
|
||||
this->DI::operator++();
|
||||
return (*this);
|
||||
}
|
||||
{
|
||||
while(( (*this) != DI{}) && !is_regular_file((**this).status()))
|
||||
this->DI::operator++();
|
||||
return (*this);
|
||||
}
|
||||
public:
|
||||
template <class... Arg>
|
||||
regular_file_only_iterator(Arg&&... arg ): DI(std::forward<Arg>(arg)...)
|
||||
{
|
||||
find_first();
|
||||
}
|
||||
regular_file_only_iterator() : DI() {}
|
||||
regular_file_only_iterator& operator++()
|
||||
{
|
||||
this->DI::operator++();
|
||||
return find_first();
|
||||
}
|
||||
|
||||
template <class... Arg>
|
||||
regular_file_only_iterator(Arg&&... arg ): DI(std::forward<Arg>(arg)...)
|
||||
{
|
||||
find_first();
|
||||
}
|
||||
|
||||
regular_file_only_iterator& operator++()
|
||||
{
|
||||
this->DI::operator++();
|
||||
return find_first();
|
||||
}
|
||||
};
|
||||
|
||||
inline regular_file_only_iterator begin(regular_file_only_iterator iter) noexcept
|
||||
@ -113,7 +118,7 @@ inline regular_file_only_iterator end(const regular_file_only_iterator&) noexcep
|
||||
inline std::string pretty_file_size(const std::experimental::filesystem::path& path) // todo: move to .cpp
|
||||
{
|
||||
try {
|
||||
std::size_t bytes = std::experimental::filesystem::file_size ( path );
|
||||
auto bytes = std::experimental::filesystem::file_size ( path );
|
||||
const char * ustr[] = { " KB", " MB", " GB", " TB" };
|
||||
std::stringstream ss;
|
||||
if (bytes < 1024)
|
||||
|
@ -61,7 +61,7 @@ namespace std {
|
||||
} // std
|
||||
|
||||
#else
|
||||
# include <experimental/filesystem>
|
||||
# include <experimental/filesystem>
|
||||
#endif
|
||||
|
||||
#ifndef __cpp_lib_experimental_filesystem
|
||||
|
Loading…
x
Reference in New Issue
Block a user