Skip to content

Commit

Permalink
Use Brace Lists to initialize objects. (microsoft#3277)
Browse files Browse the repository at this point in the history
Co-authored-by: Stephan T. Lavavej <stl@nuwen.net>
  • Loading branch information
RSilicon and StephanTLavavej committed Feb 3, 2023
1 parent 0081e8a commit 73924c1
Show file tree
Hide file tree
Showing 14 changed files with 98 additions and 98 deletions.
12 changes: 6 additions & 6 deletions stl/inc/cvt/wbuffer
Original file line number Diff line number Diff line change
Expand Up @@ -45,29 +45,29 @@ namespace stdext {
static state_type _State0;

_State = _State0;
_Loc = _STD locale(_Loc, _Pcvt);
_Loc = _STD locale{_Loc, _Pcvt};
}

explicit wbuffer_convert(_Mysb* _Strbuf)
: _Pcvt(new _Codecvt), _Mystrbuf(_Strbuf), _Status(_Unused), _Nback(0) {
static state_type _State0;

_State = _State0;
_Loc = _STD locale(_Loc, _Pcvt);
_Loc = _STD locale{_Loc, _Pcvt};
}

wbuffer_convert(_Mysb* _Strbuf, _Codecvt* _Pcvt_arg)
: _Pcvt(_Pcvt_arg), _Mystrbuf(_Strbuf), _Status(_Unused), _Nback(0) {
static state_type _State0;

_State = _State0;
_Loc = _STD locale(_Loc, _Pcvt);
_Loc = _STD locale{_Loc, _Pcvt};
}

wbuffer_convert(_Mysb* _Strbuf, _Codecvt* _Pcvt_arg, state_type _State_arg)
: _Pcvt(_Pcvt_arg), _Mystrbuf(_Strbuf), _Status(_Unused), _Nback(0) {
_State = _State_arg;
_Loc = _STD locale(_Loc, _Pcvt);
_Loc = _STD locale{_Loc, _Pcvt};
}

~wbuffer_convert() noexcept override {
Expand Down Expand Up @@ -241,13 +241,13 @@ namespace stdext {
pos_type seekoff(off_type, _STD ios_base::seekdir,
_STD ios_base::openmode = static_cast<_STD ios_base::openmode>(
_STD ios_base::in | _STD ios_base::out)) override { // change position by _Off
return pos_type(-1); // always fail
return pos_type{off_type{-1}}; // always fail
}

pos_type seekpos(pos_type,
_STD ios_base::openmode = static_cast<_STD ios_base::openmode>(
_STD ios_base::in | _STD ios_base::out)) override { // change position to _Pos
return pos_type(-1); // always fail
return pos_type{off_type{-1}}; // always fail
}

private:
Expand Down
2 changes: 1 addition & 1 deletion stl/inc/cvt/wstring
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace stdext {

void _Init(_Codecvt* _Pcvt_arg = new _Codecvt) { // initialize the object
_Pcvt = _Pcvt_arg;
_Loc = _STD locale(_Loc, _Pcvt);
_Loc = _STD locale{_Loc, _Pcvt};
_Nconv = 0;
}

Expand Down
58 changes: 29 additions & 29 deletions stl/inc/experimental/filesystem
Original file line number Diff line number Diff line change
Expand Up @@ -800,27 +800,27 @@ public:

template <class _InIt>
path& operator=(_InIt _First) {
return *this = path(_First);
return *this = path{_First};
}

template <class _Elem, class _Traits, class _Alloc>
path& operator=(const basic_string<_Elem, _Traits, _Alloc>& _Str) {
return *this = path(_Str);
return *this = path{_Str};
}

template <class _InIt>
path& assign(_InIt _First, _InIt _Last) {
return *this = path(_First, _Last);
return *this = path{_First, _Last};
}

template <class _InIt>
path& assign(_InIt _First) {
return *this = path(_First);
return *this = path{_First};
}

template <class _Elem, class _Traits, class _Alloc>
path& assign(const basic_string<_Elem, _Traits, _Alloc>& _Str) {
return *this = path(_Str);
return *this = path{_Str};
}

path& operator/=(const path& _Path) { // append copy
Expand All @@ -829,7 +829,7 @@ public:

template <class _InIt>
path& operator/=(_InIt _First) { // append NTCTS, given iterator
return append(path(_First)._Mystr);
return append(path{_First}._Mystr);
}

template <class _Elem, class _Traits, class _Alloc>
Expand All @@ -839,12 +839,12 @@ public:

template <class _InIt>
path& append(_InIt _First, _InIt _Last) { // append NTCTS
return append(path(_First, _Last)._Mystr);
return append(path{_First, _Last}._Mystr);
}

template <class _InIt>
path& append(_InIt _First) { // append NTCTS
return append(path(_First)._Mystr);
return append(path{_First}._Mystr);
}

template <class _Elem, class _Traits, class _Alloc>
Expand Down Expand Up @@ -890,7 +890,7 @@ public:

template <class _InIt>
path& concat(_InIt _First, _InIt _Last) { // concatenate NTCTS
return concat(path(_First, _Last)._Mystr);
return concat(path{_First, _Last}._Mystr);
}

template <class _Elem>
Expand All @@ -900,12 +900,12 @@ public:

template <class _InIt, enable_if_t<_Is_iterator_v<_InIt>, int> = 0>
path& concat(_InIt _First) { // concatenate NTCTS
return concat(path(_First)._Mystr);
return concat(path{_First}._Mystr);
}

template <class _Elem, enable_if_t<!_Is_iterator_v<_Elem>, int> = 0>
path& concat(_Elem _Val) { // concatenate element
return concat(path(basic_string<_Elem>(1, _Val))._Mystr);
return concat(path{basic_string<_Elem>(1, _Val)}._Mystr);
}

template <class _Elem, class _Traits, class _Alloc>
Expand Down Expand Up @@ -956,9 +956,9 @@ public:

path& replace_extension(const path& _Newext = {}) { // replace extension with _Newext
if (_Newext.empty() || _Newext.c_str()[0] == _FS_PERIOD) {
*this = parent_path() / path((stem().native() + _Newext.native()));
*this = parent_path() / path{stem().native() + _Newext.native()};
} else {
*this = parent_path() / path((stem().native() + _FS_PERIOD + _Newext.native()));
*this = parent_path() / path{stem().native() + _FS_PERIOD + _Newext.native()};
}

return *this;
Expand Down Expand Up @@ -1064,20 +1064,20 @@ public:
}

_NODISCARD path root_name() const {
return path(_Mystr.substr(0, _Prefix_end()));
return path{_Mystr.substr(0, _Prefix_end())};
}

_NODISCARD path root_directory() const {
const size_t _Idx = _Prefix_end();
if (_Idx < _Mystr.size() && _FS_ISSEP(_Mystr[_Idx])) {
return path(string_type(1, _FS_PREF));
return path{string_type(1, _FS_PREF)};
} else {
return {};
}
}

_NODISCARD path root_path() const {
return path(_Mystr.c_str(), _Mystr.c_str() + _Root_end());
return path{_Mystr.c_str(), _Mystr.c_str() + _Root_end()};
}

_NODISCARD path relative_path() const {
Expand All @@ -1086,7 +1086,7 @@ public:
++_Idx; // skip extra '/' after root
}

return path(_Mystr.substr(_Idx));
return path{_Mystr.substr(_Idx)};
}

_NODISCARD path parent_path() const {
Expand All @@ -1101,14 +1101,14 @@ public:
}

_NODISCARD path filename() const {
return empty() ? path{} : path(*--end());
return empty() ? path{} : path{*--end()};
}

_NODISCARD path stem() const { // pick off stem (basename) in filename (leaf) before dot
string_type _Str0 = filename().native();
string_type _Str1 = extension().native();
_Str0.resize(_Str0.size() - _Str1.size());
return path(_Str0);
return path{_Str0};
}

_NODISCARD path extension() const { // pick off .extension in filename (leaf), including dot
Expand All @@ -1118,7 +1118,7 @@ public:
|| _Str.size() == 1 // only .
|| (_Str.size() == 2 && _Str[0] == _FS_PERIOD && _Str[1] == _FS_PERIOD) // only ..
? path{}
: path(_Str.substr(_Idx));
: path{_Str.substr(_Idx)};
}

_NODISCARD bool empty() const noexcept {
Expand Down Expand Up @@ -1264,7 +1264,7 @@ template <class _InIt, enable_if_t<_Is_iterator_v<_InIt>, int> = 0>
_NODISCARD path u8path(_InIt _First, _InIt _Last) { // make path from [_First, _Last) UTF8, given iterators
string _Str(_First, _Last);
path::string_type _Str_out;
return path(_Path_cvt<_Char8_t, _Pchar>::_Cvt(_Str_out, _Str.c_str(), _Str.size()));
return path{_Path_cvt<_Char8_t, _Pchar>::_Cvt(_Str_out, _Str.c_str(), _Str.size())};
}

template <class _InIt, enable_if_t<_Is_iterator_v<_InIt>, int> = 0>
Expand All @@ -1275,13 +1275,13 @@ _NODISCARD path u8path(_InIt _First) { // make path from NTBS UTF8, given iterat
}

path::string_type _Str_out;
return path(_Path_cvt<_Char8_t, _Pchar>::_Cvt(_Str_out, _Str.c_str(), _Str.size()));
return path{_Path_cvt<_Char8_t, _Pchar>::_Cvt(_Str_out, _Str.c_str(), _Str.size())};
}

template <class _Traits, class _Alloc>
_NODISCARD path u8path(const basic_string<char, _Traits, _Alloc>& _Str) { // make path from arbitrary char string UTF8
path::string_type _Str_out;
return path(_Path_cvt<_Char8_t, _Pchar>::_Cvt(_Str_out, _Str.c_str(), _Str.size()));
return path{_Path_cvt<_Char8_t, _Pchar>::_Cvt(_Str_out, _Str.c_str(), _Str.size())};
}

class filesystem_error : public system_error { // base of all filesystem-error exceptions
Expand Down Expand Up @@ -1550,10 +1550,10 @@ private:
void _Form_name(typename string_type::value_type* _Filename, file_type _Ftype) {
if constexpr (_Prefix_directory::value) {
// set entry to _Mydirpath/_Filename
_Myentry.assign(_Mydirpath / path(_Filename), file_status(_Ftype));
_Myentry.assign(_Mydirpath / path{_Filename}, file_status{_Ftype});
} else {
// set entry to _Filename
_Myentry.assign(path(_Filename), file_status(_Ftype));
_Myentry.assign(path{_Filename}, file_status{_Ftype});
}
}

Expand Down Expand Up @@ -2155,7 +2155,7 @@ _NODISCARD inline path current_path(error_code& _Code) {
_Code = make_error_code(errc::operation_not_permitted);
return {};
}
return path(_Dest);
return path{_Dest};
}

inline void current_path(const path& _Path) { // set current working directory
Expand Down Expand Up @@ -2457,7 +2457,7 @@ _NODISCARD inline path read_symlink(const path& _Path,
return {};
}
_Pchar _Dest[_MAX_FILESYS_NAME];
return path(_Symlink_get(_Dest, _Path.c_str()));
return path{_Symlink_get(_Dest, _Path.c_str())};
}

inline bool remove(const path& _Path) { // remove a file
Expand Down Expand Up @@ -2613,7 +2613,7 @@ _NODISCARD inline file_status status(const path& _Path, error_code& _Code) noexc
_Code.clear();
perms _Mode;
const file_type _Ftype = _Stat(_Path.c_str(), &_Mode);
return file_status(_Ftype, _Mode);
return file_status{_Ftype, _Mode};
}

_NODISCARD inline bool status_known(file_status _Stat) noexcept {
Expand All @@ -2630,7 +2630,7 @@ _NODISCARD inline file_status symlink_status(const path& _Path, error_code& _Cod
const file_type _Ftype = _Lstat(_Path.c_str(), &_Mode);

_Code.clear();
return file_status(_Ftype, _Mode);
return file_status{_Ftype, _Mode};
}

_NODISCARD inline path system_complete(const path& _Path) {
Expand Down
32 changes: 16 additions & 16 deletions stl/inc/filesystem
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ namespace filesystem {
// * \\server\share
// We parse \\server as root-name, \ as root-directory, and share as the first element in relative-path.
// Technically, Windows considers all of \\server\share the logical "root", but for purposes
// of decomposition we want those split, so that path(R"(\\server\share)").replace_filename("other_share")
// of decomposition we want those split, so that path{R"(\\server\share)"}.replace_filename("other_share")
// is \\server\other_share
// * \\?\device
// * \??\device
Expand Down Expand Up @@ -707,12 +707,12 @@ namespace filesystem {
path& operator/=(const path& _Other) {
// set *this to the path lexically resolved by _Other relative to *this
// examples:
// path("cat") / "c:/dog"; // yields "c:/dog"
// path("cat") / "c:"; // yields "c:"
// path("c:") / ""; // yields "c:"
// path("c:cat") / "/dog"; // yields "c:/dog"
// path("c:cat") / "c:dog"; // yields "c:cat/dog"
// path("c:cat") / "d:dog"; // yields "d:dog"
// path{"cat"} / "c:/dog"; // yields "c:/dog"
// path{"cat"} / "c:"; // yields "c:"
// path{"c:"} / ""; // yields "c:"
// path{"c:cat"} / "/dog"; // yields "c:/dog"
// path{"c:cat"} / "c:dog"; // yields "c:cat/dog"
// path{"c:cat"} / "d:dog"; // yields "d:dog"
// several places herein quote the standard, but the standard's variable p is replaced with _Other

if (_Other.is_absolute()) { // if _Other.is_absolute(), then op=(_Other)
Expand Down Expand Up @@ -772,18 +772,18 @@ namespace filesystem {

template <class _Src, enable_if_t<_Is_Source<_Src>, int> = 0>
path& operator/=(const _Src& _Source) {
return operator/=(path(_Source));
return operator/=(path{_Source});
}

template <class _Src, enable_if_t<_Is_Source<_Src>, int> = 0>
path& append(const _Src& _Source) {
return operator/=(path(_Source));
return operator/=(path{_Source});
}

template <class _InIt>
path& append(_InIt _First, _InIt _Last) {
static_assert(_Is_EcharT<_Iter_value_t<_InIt>>, "invalid value_type, see N4810 29.11.4 [fs.req]/3");
return operator/=(path(_First, _Last));
return operator/=(path{_First, _Last});
}

path& operator+=(const path& _Added) { // concat _Added to native()
Expand Down Expand Up @@ -816,23 +816,23 @@ namespace filesystem {

template <class _Src, enable_if_t<_Is_Source<_Src>, int> = 0>
path& operator+=(const _Src& _Added) { // concat _Added to native()
return operator+=(path(_Added)._Text);
return operator+=(path{_Added}._Text);
}

template <class _EcharT, enable_if_t<_Is_EcharT<_EcharT>, int> = 0>
path& operator+=(const _EcharT _Added) { // concat _Added to native()
return operator+=(path(&_Added, &_Added + 1)._Text);
return operator+=(path{&_Added, &_Added + 1}._Text);
}

template <class _Src, enable_if_t<_Is_Source<_Src>, int> = 0>
path& concat(const _Src& _Added) { // concat _Added to native()
return operator+=(path(_Added)._Text);
return operator+=(path{_Added}._Text);
}

template <class _InIt>
path& concat(_InIt _First, _InIt _Last) { // concat [_First, _Last) to native()
static_assert(_Is_EcharT<_Iter_value_t<_InIt>>, "invalid value_type, see N4810 29.11.4 [fs.req]/3");
return operator+=(path(_First, _Last)._Text);
return operator+=(path{_First, _Last}._Text);
}

void clear() noexcept { // set *this to the empty path
Expand Down Expand Up @@ -1374,14 +1374,14 @@ namespace filesystem {

_EXPORT_STD template <class _Src, enable_if_t<_Is_Source<_Src>, int> = 0>
_CXX20_DEPRECATE_U8PATH _NODISCARD path u8path(const _Src& _Source) { // construct a path from UTF-8 _Source
return path(_Convert_Source_to_wide(_Source, _Utf8_conversion{}));
return path{_Convert_Source_to_wide(_Source, _Utf8_conversion{})};
}

_EXPORT_STD template <class _InIt>
_CXX20_DEPRECATE_U8PATH _NODISCARD path u8path(_InIt _First, _InIt _Last) {
// construct a path from UTF-8 [_First, _Last)
static_assert(_Is_EcharT<_Iter_value_t<_InIt>>, "invalid value_type, see N4810 29.11.4 [fs.req]/3");
return path(_Convert_range_to_wide(_First, _Last, _Utf8_conversion{}));
return path{_Convert_range_to_wide(_First, _Last, _Utf8_conversion{})};
}

template <class _Base_iter>
Expand Down
Loading

0 comments on commit 73924c1

Please sign in to comment.