Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3f25a77

Browse files
committed
#209-test slices
Completed. Validated.A few fixes and added `operator*()`.
1 parent43f4bbd commit3f25a77

File tree

1 file changed

+62
-36
lines changed

1 file changed

+62
-36
lines changed

‎cpp-strings/cppstrings.h‎

Lines changed: 62 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1846,9 +1846,7 @@ namespace pcs // i.e. "pythonic c++ strings"
18461846
staticconstexpr IntT DEFAULT{ std::numeric_limits<IntT>::min()};
18471847

18481848
//--- Constructors / Destructor -------------------
1849-
Slice()noexcept =default;//!< Default constructor
1850-
1851-
Slice(const IntT start,const IntT stop,const IntT step)noexcept//!< Valued constructor
1849+
Slice(const IntT start = DEFAULT,const IntT stop = DEFAULT,const IntT step = DEFAULT)noexcept//!< Valued constructor
18521850
: _start(start)
18531851
, _stop(stop)
18541852
, _step(step)
@@ -1873,15 +1871,21 @@ namespace pcs // i.e. "pythonic c++ strings"
18731871
return _step ==0 ?true : _step >0 ? _index >= _stop : _index <= _stop;
18741872
}
18751873

1876-
inlineconst IntToperator++()noexcept//!< iterates one step, pre-increment. Caution:returnedindex may be out of bounds. Check '!end()' beforeusing its value.
1874+
inlineSliceoperator++()noexcept//!< iterates one step, pre-increment. Caution: index may be out of bounds. Check '!end()' beforedereferencing the slice.
18771875
{
1878-
return _index += _step;
1876+
_index += _step;
1877+
return *this;
18791878
}
18801879

1881-
inlineconst IntToperator++(int)noexcept//!< iterates one step, post-increment. Caution:returnedindex may be out of bounds. Check '!end()' beforeusing its value.
1880+
inlineSliceoperator++(int)noexcept//!< iterates one step, post-increment. Caution: index may be out of bounds. Check '!end()' beforedereferencing the slice.
18821881
{
18831882
_index += _step;
1884-
return _index - _step;
1883+
return *this;
1884+
}
1885+
1886+
inlineconst IntToperator*()noexcept//!< dereferences the slice.
1887+
{
1888+
return _index;
18851889
}
18861890

18871891

@@ -1896,16 +1900,38 @@ namespace pcs // i.e. "pythonic c++ strings"
18961900
{
18971901
if (_start == DEFAULT)
18981902
_start =0;
1899-
elseif (_start <0)
1903+
elseif (_start <0) {
19001904
_start += str_size;
1901-
1902-
if (_stop == DEFAULT)
1903-
_stop = str_size;
1904-
elseif (_stop <0)
1905+
if (_start <0)
1906+
_start =0;
1907+
}
1908+
elseif (_start >= str_size)
1909+
_start = str_size -1;
1910+
1911+
if (_stop == DEFAULT) {
1912+
if (_step <0 && _step != DEFAULT)
1913+
_stop =0;
1914+
else
1915+
_stop = str_size;
1916+
}
1917+
elseif (_stop <0) {
19051918
_stop += str_size;
1919+
if (_stop <0)
1920+
_stop =0;
1921+
}
1922+
elseif (_stop > str_size)
1923+
_stop = str_size;
19061924

19071925
if (_step == DEFAULT)
19081926
_step =1;
1927+
if (_step <0) {
1928+
if (_start <= _stop)
1929+
_step =0;// will force end() to true
1930+
}
1931+
else {
1932+
if (_start >= _stop)
1933+
_step =0;// will force end() to true
1934+
}
19091935

19101936
return _index = _start;
19111937
}
@@ -1917,11 +1943,11 @@ namespace pcs // i.e. "pythonic c++ strings"
19171943
requires std::is_signed_v<IntT>
19181944
structStartSlice :publicSlice<IntT>
19191945
{
1920-
//--- Constructors / Destructor -------------------
1921-
StartSlice()noexcept =default;//!< Default constructor
1946+
using MyBaseClass = Slice<IntT>;
19221947

1923-
inlineStartSlice(const IntT start)noexcept//!< Valued constructor
1924-
: Slice(start, Slice::DEFAULT,1)
1948+
//--- Constructors / Destructor -------------------
1949+
inlineStartSlice(const IntT start = MyBaseClass::DEFAULT)noexcept//!< Valued constructor
1950+
: MyBaseClass(start, MyBaseClass::DEFAULT,1)
19251951
{}
19261952

19271953
virtual~StartSlice()noexcept =default;//!< Default destructor.
@@ -1933,11 +1959,11 @@ namespace pcs // i.e. "pythonic c++ strings"
19331959
requires std::is_signed_v<IntT>
19341960
structStopSlice :publicSlice<IntT>
19351961
{
1936-
//--- Constructors / Destructor -------------------
1937-
StopSlice()noexcept =default;//!< Default constructor
1962+
using MyBaseClass = Slice<IntT>;
19381963

1939-
inlineStopSlice(const IntT stop)noexcept//!< Valued constructor
1940-
: Slice(Slice::DEFAULT, stop,1)
1964+
//--- Constructors / Destructor -------------------
1965+
inlineStopSlice(const IntT stop = MyBaseClass::DEFAULT)noexcept//!< Valued constructor
1966+
: MyBaseClass(MyBaseClass::DEFAULT, stop,1)
19411967
{}
19421968

19431969
virtual~StopSlice()noexcept =default;//!< Default destructor.
@@ -1949,11 +1975,11 @@ namespace pcs // i.e. "pythonic c++ strings"
19491975
requires std::is_signed_v<IntT>
19501976
structStepSlice :publicSlice<IntT>
19511977
{
1952-
//--- Constructors / Destructor -------------------
1953-
StepSlice()noexcept =default;//!< Default constructor
1978+
using MyBaseClass = Slice<IntT>;
19541979

1955-
inlineStepSlice(const IntT step)noexcept//!< Valued constructor
1956-
: Slice(Slice::DEFAULT, Slice::DEFAULT, step)
1980+
//--- Constructors / Destructor -------------------
1981+
inlineStepSlice(const IntT step = MyBaseClass::DEFAULT)noexcept//!< Valued constructor
1982+
: MyBaseClass(MyBaseClass::DEFAULT, MyBaseClass::DEFAULT, step)
19571983
{}
19581984

19591985
virtual~StepSlice()noexcept =default;//!< Default destructor.
@@ -1965,11 +1991,11 @@ namespace pcs // i.e. "pythonic c++ strings"
19651991
requires std::is_signed_v<IntT>
19661992
structStartStopSlice :publicSlice<IntT>
19671993
{
1968-
//--- Constructors / Destructor -------------------
1969-
StartStopSlice()noexcept =default;//!< Default constructor
1994+
using MyBaseClass = Slice<IntT>;
19701995

1971-
inlineStartStopSlice(const IntT start,const IntT stop)noexcept//!< Valued constructor
1972-
: Slice(start, stop,1)
1996+
//--- Constructors / Destructor -------------------
1997+
inlineStartStopSlice(const IntT start = MyBaseClass::DEFAULT,const IntT stop = MyBaseClass::DEFAULT)noexcept//!< Valued constructor
1998+
: MyBaseClass(start, stop,1)
19731999
{}
19742000

19752001
virtual~StartStopSlice()noexcept =default;//!< Default destructor.
@@ -1981,11 +2007,11 @@ namespace pcs // i.e. "pythonic c++ strings"
19812007
requires std::is_signed_v<IntT>
19822008
structStartStepSlice :publicSlice<IntT>
19832009
{
1984-
//--- Constructors / Destructor -------------------
1985-
StartStepSlice()noexcept =default;//!< Default constructor
2010+
using MyBaseClass = Slice<IntT>;
19862011

1987-
inlineStartStepSlice(const IntT start,const IntT step)noexcept//!< Valued constructor
1988-
: Slice(start, Slice::DEFAULT, step)
2012+
//--- Constructors / Destructor -------------------
2013+
inlineStartStepSlice(const IntT start = MyBaseClass::DEFAULT,const IntT step = MyBaseClass::DEFAULT)noexcept//!< Valued constructor
2014+
: MyBaseClass(start, MyBaseClass::DEFAULT, step)
19892015
{}
19902016

19912017
virtual~StartStepSlice()noexcept =default;//!< Default destructor.
@@ -1998,11 +2024,11 @@ namespace pcs // i.e. "pythonic c++ strings"
19982024
requires std::is_signed_v<IntT>
19992025
structStopStepSlice :publicSlice<IntT>
20002026
{
2001-
//--- Constructors / Destructor -------------------
2002-
StopStepSlice()noexcept =default;//!< Default constructor
2027+
using MyBaseClass = Slice<IntT>;
20032028

2004-
inlineStopStepSlice(const IntT stop,const IntT step)noexcept//!< Valued constructor
2005-
: Slice(Slice::DEFAULT, stop, step)
2029+
//--- Constructors / Destructor -------------------
2030+
inlineStopStepSlice(const IntT stop = MyBaseClass::DEFAULT,const IntT step = MyBaseClass::DEFAULT)noexcept//!< Valued constructor
2031+
: MyBaseClass(MyBaseClass::DEFAULT, stop, step)
20062032
{}
20072033

20082034
virtual~StopStepSlice()noexcept =default;//!< Default destructor.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp