You can subscribe to this list here.
| 2005 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(80) |
Aug
(36) |
Sep
(120) |
Oct
(89) |
Nov
(57) |
Dec
(22) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2006 |
Jan
(308) |
Feb
(66) |
Mar
(88) |
Apr
(54) |
May
(43) |
Jun
(40) |
Jul
(33) |
Aug
(1) |
Sep
(7) |
Oct
(65) |
Nov
(19) |
Dec
(10) |
| 2007 |
Jan
(5) |
Feb
(8) |
Mar
(7) |
Apr
|
May
(7) |
Jun
|
Jul
(5) |
Aug
(3) |
Sep
(1) |
Oct
|
Nov
|
Dec
|
| 2008 |
Jan
|
Feb
|
Mar
(5) |
Apr
|
May
(5) |
Jun
(21) |
Jul
(27) |
Aug
(6) |
Sep
|
Oct
(1) |
Nov
(5) |
Dec
(10) |
| 2009 |
Jan
(67) |
Feb
(3) |
Mar
(26) |
Apr
(2) |
May
|
Jun
(1) |
Jul
|
Aug
(2) |
Sep
(10) |
Oct
(18) |
Nov
(20) |
Dec
(3) |
| 2010 |
Jan
|
Feb
|
Mar
(1) |
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
|
Sep
(9) |
Oct
(3) |
Nov
|
Dec
|
| 2011 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(7) |
Jul
|
Aug
|
Sep
(39) |
Oct
(43) |
Nov
(7) |
Dec
|
| 2012 |
Jan
|
Feb
|
Mar
|
Apr
(6) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2013 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(7) |
Jul
|
Aug
(1) |
Sep
|
Oct
|
Nov
|
Dec
|
|
From: <syn...@us...> - 2009-08-16 20:34:00
|
Revision: 1016
http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1016&view=rev
Author: syntheticpp
Date: 2009-08-16 20:33:52 +0000 (Sun, 16 Aug 2009)
Log Message:
-----------
undo removing warning.
https://sourceforge.net/forum/message.php?msg_id=7564865
Modified Paths:
--------------
trunk/include/loki/Singleton.h
Modified: trunk/include/loki/Singleton.h
===================================================================
--- trunk/include/loki/Singleton.h 2009-08-16 20:29:58 UTC (rev 1015)
+++ trunk/include/loki/Singleton.h 2009-08-16 20:33:52 UTC (rev 1016)
@@ -815,8 +815,8 @@
{
if (destroyed_)
{
+ LifetimePolicy<T>::OnDeadReference();
destroyed_ = false;
- LifetimePolicy<T>::OnDeadReference();
}
pInstance_ = CreationPolicy<T>::Create();
LifetimePolicy<T>::ScheduleDestruction(pInstance_,
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <syn...@us...> - 2009-08-16 20:30:16
|
Revision: 1015
http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1015&view=rev
Author: syntheticpp
Date: 2009-08-16 20:29:58 +0000 (Sun, 16 Aug 2009)
Log Message:
-----------
fix bug
https://sourceforge.net/tracker/?func=detail&atid=396644&aid=2807089&group_id=29557
Modified Paths:
--------------
trunk/include/loki/Threads.h
Modified: trunk/include/loki/Threads.h
===================================================================
--- trunk/include/loki/Threads.h 2009-04-11 06:02:59 UTC (rev 1014)
+++ trunk/include/loki/Threads.h 2009-08-16 20:29:58 UTC (rev 1015)
@@ -92,6 +92,9 @@
#define LOKI_THREADS_MUTEX_CTOR(x)
#define LOKI_THREADS_ATOMIC_FUNCTIONS \
+ private: \
+ static CRITICAL_SECTION atomic_mutex_; \
+ public: \
static IntType AtomicMultiply(volatile IntType& lval, const IntType val) \
{ \
::EnterCriticalSection( &atomic_mutex_ ); \
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: XuAlbert <alb...@ho...> - 2009-06-03 02:44:02
|
_________________________________________________________________ 上Windows Live 中国首页,下载最新版Messenger! http://www.windowslive.cn |
|
From: <ric...@us...> - 2009-04-11 06:03:09
|
Revision: 1014
http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1014&view=rev
Author: rich_sposato
Date: 2009-04-11 06:02:59 +0000 (Sat, 11 Apr 2009)
Log Message:
-----------
Added tests for comparison operators for SmartPtr.
Modified Paths:
--------------
trunk/test/SmartPtr/main.cpp
Modified: trunk/test/SmartPtr/main.cpp
===================================================================
--- trunk/test/SmartPtr/main.cpp 2009-04-11 06:01:06 UTC (rev 1013)
+++ trunk/test/SmartPtr/main.cpp 2009-04-11 06:02:59 UTC (rev 1014)
@@ -373,6 +373,102 @@
NonConstBase_RefLink_NoConvert_Assert_DontPropagate_ptr p5;
NonConstBase_RefLink_NoConvert_Assert_DontPropagate_ptr p6( new BaseClass );
+ BaseClass * pBare1 = GetImpl( p1 );
+ BaseClass * pBare2 = GetImpl( p2 );
+ BaseClass * pBare6 = GetImpl( p6 );
+ const bool is1LessThan2 = ( pBare1 < pBare2 );
+ const bool is1LessThan6 = ( pBare1 < pBare6 );
+ const bool is2LessThan6 = ( pBare2 < pBare6 );
+ assert( pBare1 != pBare2 );
+ assert( pBare1 != pBare6 );
+ assert( pBare2 != pBare6 );
+ assert( p1 == pBare1 );
+ assert( p2 == pBare2 );
+ assert( p6 == pBare6 );
+ assert( pBare1 == p1 );
+ assert( pBare2 == p2 );
+ assert( pBare6 == p6 );
+ assert( pBare2 != p1 );
+ assert( p1 != pBare2 );
+
+ if ( is1LessThan2 )
+ {
+ assert( p1 < p2 );
+ assert( p1 <= p2 );
+ assert( p1 != p2 );
+ assert( p2 > p1 );
+ assert( p2 >= p1 );
+ assert( p1 < pBare2 );
+ assert( p1 <= pBare2 );
+ assert( pBare2 > p1 );
+ assert( pBare2 >= p1 );
+ }
+ else
+ {
+ assert( p2 < p1 );
+ assert( p2 <= p1 );
+ assert( p2 != p1 );
+ assert( p1 > p2 );
+ assert( p1 >= p2 );
+ assert( p2 < pBare1 );
+ assert( p2 <= pBare1 );
+ assert( p2 != pBare1 );
+ assert( pBare1 > p2 );
+ assert( pBare1 >= p2 );
+ }
+
+ if ( is1LessThan6 )
+ {
+ assert( p1 < p6 );
+ assert( p1 <= p6 );
+ assert( p1 != p6 );
+ assert( p6 > p1 );
+ assert( p6 >= p1 );
+ assert( p1 < pBare6 );
+ assert( p1 <= pBare6 );
+ assert( pBare6 > p1 );
+ assert( pBare6 >= p1 );
+ }
+ else
+ {
+ assert( p6 < p1 );
+ assert( p6 <= p1 );
+ assert( p6 != p1 );
+ assert( p1 > p6 );
+ assert( p1 >= p6 );
+ assert( p6 < pBare1 );
+ assert( p6 <= pBare1 );
+ assert( p6 != pBare1 );
+ assert( pBare1 > p6 );
+ assert( pBare1 >= p6 );
+ }
+
+ if ( is2LessThan6 )
+ {
+ assert( p2 < p6 );
+ assert( p2 <= p6 );
+ assert( p2 != p6 );
+ assert( p6 > p2 );
+ assert( p6 >= p2 );
+ assert( p2 < pBare6 );
+ assert( p2 <= pBare6 );
+ assert( pBare6 > p2 );
+ assert( pBare6 >= p2 );
+ }
+ else
+ {
+ assert( p6 < p2 );
+ assert( p6 <= p2 );
+ assert( p6 != p2 );
+ assert( p2 > p6 );
+ assert( p2 >= p6 );
+ assert( p6 < pBare2 );
+ assert( p6 <= pBare2 );
+ assert( p6 != pBare2 );
+ assert( pBare2 > p6 );
+ assert( pBare2 >= p6 );
+ }
+
// p1 <---> p3 and p2 <---> p4 and p5 and p6
assert( p1 == p3 );
assert( p1 != p2 );
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ric...@us...> - 2009-04-11 06:01:14
|
Revision: 1013
http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1013&view=rev
Author: rich_sposato
Date: 2009-04-11 06:01:06 +0000 (Sat, 11 Apr 2009)
Log Message:
-----------
Fixed bug 2747377 by changing order of operands.
Modified Paths:
--------------
trunk/include/loki/SmartPtr.h
Modified: trunk/include/loki/SmartPtr.h
===================================================================
--- trunk/include/loki/SmartPtr.h 2009-03-31 21:56:08 UTC (rev 1012)
+++ trunk/include/loki/SmartPtr.h 2009-04-11 06:01:06 UTC (rev 1013)
@@ -1531,7 +1531,7 @@
>
inline bool operator==(const SmartPtr<T, OP, CP, KP, SP, CNP1 >& lhs,
U* rhs)
- { return GetImpl(lhs) == rhs; }
+ { return ( GetImpl( lhs ) == rhs ); }
////////////////////////////////////////////////////////////////////////////////
/// operator== for lhs = raw pointer, rhs = SmartPtr
@@ -1550,7 +1550,7 @@
>
inline bool operator==(U* lhs,
const SmartPtr<T, OP, CP, KP, SP, CNP1 >& rhs)
- { return rhs == lhs; }
+ { return ( GetImpl( rhs ) == lhs ); }
////////////////////////////////////////////////////////////////////////////////
/// operator!= for lhs = SmartPtr, rhs = raw pointer
@@ -1569,7 +1569,7 @@
>
inline bool operator!=(const SmartPtr<T, OP, CP, KP, SP, CNP >& lhs,
U* rhs)
- { return !(lhs == rhs); }
+ { return ( GetImpl( lhs ) != rhs ); }
////////////////////////////////////////////////////////////////////////////////
/// operator!= for lhs = raw pointer, rhs = SmartPtr
@@ -1588,7 +1588,7 @@
>
inline bool operator!=(U* lhs,
const SmartPtr<T, OP, CP, KP, SP, CNP >& rhs)
- { return rhs != lhs; }
+ { return ( GetImpl( rhs ) != lhs ); }
////////////////////////////////////////////////////////////////////////////////
/// operator< for lhs = SmartPtr, rhs = raw pointer
@@ -1629,7 +1629,7 @@
inline bool operator<(U* lhs,
const SmartPtr<T, OP, CP, KP, SP, CNP >& rhs)
{
- return ( GetImpl( rhs ) < lhs );
+ return ( lhs < GetImpl( rhs ) );
}
////////////////////////////////////////////////////////////////////////////////
@@ -1649,7 +1649,7 @@
>
inline bool operator>(const SmartPtr<T, OP, CP, KP, SP, CNP >& lhs,
U* rhs)
- { return rhs < lhs; }
+ { return rhs < GetImpl( lhs ); }
////////////////////////////////////////////////////////////////////////////////
/// operator> for lhs = raw pointer, rhs = SmartPtr
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ric...@us...> - 2009-03-31 21:56:20
|
Revision: 1012
http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1012&view=rev
Author: rich_sposato
Date: 2009-03-31 21:56:08 +0000 (Tue, 31 Mar 2009)
Log Message:
-----------
Added structs to declare typedefs for various exception policies.
Modified Paths:
--------------
trunk/include/loki/Checker.h
trunk/test/Checker/main.cpp
Modified: trunk/include/loki/Checker.h
===================================================================
--- trunk/include/loki/Checker.h 2009-03-17 18:21:12 UTC (rev 1011)
+++ trunk/include/loki/Checker.h 2009-03-31 21:56:08 UTC (rev 1012)
@@ -39,7 +39,7 @@
@par Class & Data Invariants
The ContractChecker and StaticChecker define invariants as "expressions that
- are true for particular data". They uses a function which returns true if all
+ are true for particular data". They call a function which returns true if all
data are valid, and returns false if any datum is invalid. This is called the
validator function, and the host class or function provides a pointer to it.
The validator could also assert for any invariant which fails rather than
@@ -67,6 +67,40 @@
- Basic guarantee: A function will not leak resources and data will remain
in a valid state if an exception occurs. (Which I call either the no-leak
or no-break guarantee depending on context.)
+
+ @par Writing Your Own Policies
+ Loki provides several exception policies for ContractChecker. These policies
+ assert if an object changed or a function threw an exception. If you prefer
+ policies that log failures to a file, pop-up a message box, notify your unit-
+ test framework, or whatever else, you can easily write your own policies.
+ Your policy class should have two functions, a constructor and a Check
+ function, both of which accept a pointer to const instance of the host class.
+ Your policy class will become a base class of ContractChecker. Check should
+ return true if all is okay, and false if any failure was detected. Check
+ should never throw any exceptions since it is called from ContractChecker's
+ destructor. You may add other functions to the policy class. This code
+ snippet shows the signatures for the two required functions.
+ @code
+ class YourPolicy
+ { public:
+ explicit YourPolicy( const Host * );
+ bool Check( const Host * ) const;
+ }
+ @endcode
+ Loki provides two exception policies for StaticChecker - one that asserts if
+ an exception occurred, and one that does not care about exceptions. You can
+ make your own policy to log failures, send an email, file a bug report, or do
+ whatever. Just write a policy with a default constructor and a function call
+ Check which look like those shown below. Make sure your Check function never
+ throws any exceptions. Any additional functions or features of the policy
+ are up to you.
+ @code
+ class YourPolicy
+ { public:
+ YourPolicy();
+ bool Check() const;
+ }
+ @endcode
*/
// ----------------------------------------------------------------------------
@@ -81,6 +115,7 @@
@par Requirements For Host Class:
This policy imposes no requirements on a host class.
*/
+
template < class Host >
class CheckForNoThrow
{
@@ -173,7 +208,8 @@
/** @class CheckForEquality
@par Exception Safety Level:
- This exception-checking policy class for ContractChecker asserts if a copy of the host differs from the host object regardless of whether an exception occurs.
+ This exception-checking policy class for ContractChecker asserts if a copy of
+ the host differs from the host object regardless of whether an exception occurs.
Host classes can use this policy to show which member functions never change
data members, and thereby provide the strong exception safety level by default.
@@ -241,23 +277,23 @@
something is wrong.
- Or it could assert if anything is wrong.
- Ideally, it should be private.
- -# Implement similar functions to check for pre-conditions and post-conditions.
- Functions which verify pre-conditions and post-conditions do not need to
- check all class invariants, just conditions specific to certain public
- functions in the host class.
- -# Declare some typedef's inside the class declaration like these. Make one
- typedef for each exception policy you use. I typedef'ed the CheckForNothing
- policy as CheckInvariants because even if a function can't provide either the
- no-throw nor the no-change policies, it should still make sure the object
- remains in a valid state.
- - typedef ::Loki::ContractChecker< Host, ::Loki::CheckForNoThrow > CheckForNoThrow;
- - typedef ::Loki::ContractChecker< Host, ::Loki::CheckForNoChange > CheckForNoChange;
- - typedef ::Loki::ContractChecker< Host, ::Loki::CheckForEquality > CheckForEquality;
- - typedef ::Loki::ContractChecker< Host, ::Loki::CheckForNothing > CheckInvariants;
- -# Construct a checker near the top of each member function - except in the
- validator member function. Pass the this pointer and the address of your
- validator function into the checker's constructor. You may also pass in pointers
- to function which check pre- and post-conditions.
+ - It should never throw an exception.
+ -# Optionally implement similar functions to check for pre-conditions and post-
+ conditions. Functions which verify pre-conditions and post-conditions do
+ not need to check all class invariants, just conditions specific to certain
+ public functions in the host class. The post-condition function should never
+ throw exceptions.
+ -# Add this line in the class declaration:
+ - typedef ::Loki::CheckFor< Host > CheckFor;
+ -# Add one of these lines at the top of various class member functions to
+ construct a checker near the top of each public function. You may also pass
+ in pointers to functions which check pre- and post-conditions.
+ - CheckFor::NoChangeOrThrow checker( this, &Host::IsValid );
+ - CheckFor::NoThrow checker( this, &Host::IsValid );
+ - CheckFor::NoChange checker( this, &Host::IsValid );
+ - CheckFor::Equality checker( this, &Host::IsValid );
+ - CheckFor::Invariants checker( this, &Host::IsValid );
+ -# Use these guidelines to decide which policy to use inside which function:
- If the function never throws, then use the CheckForNoThrow policy.
- If the function never changes any data members, then use CheckForEquality
policy.
@@ -362,6 +398,26 @@
// ----------------------------------------------------------------------------
+/** @struct CheckFor
+ This struct declares types of checkers used to validate a host object. All of
+ Loki's exception-checking policies are named here as typedef's so host classes
+ have a one-stop convenience place for declaring them. If you write your own
+ exception policies for ContractChecker, you might want to also write a struct
+ similiar to CheckFor to conveniently declare all your policies.
+ */
+template < class Host >
+struct CheckFor
+{
+ // These lines declare checkers for non-static functions in a host class.
+ typedef ContractChecker< Host, CheckForNoChangeOrThrow > NoChangeOrThrow;
+ typedef ContractChecker< Host, CheckForNoThrow > NoThrow;
+ typedef ContractChecker< Host, CheckForNoChange > NoChange;
+ typedef ContractChecker< Host, CheckForEquality > Equality;
+ typedef ContractChecker< Host, CheckForNothing > Invariants;
+};
+
+// ----------------------------------------------------------------------------
+
/** @class CheckStaticForNoThrow
@par Exception Safety Level:
@@ -410,18 +466,25 @@
- The function should return true if everything is okay, but false if
something is wrong.
- Or it could assert if anything is wrong.
- -# If the checker is for static functions within a class, declare typedef's
- inside the class declaration like these. Make one typedef for each policy
- you use. I typedef'ed the CheckForNothing policy as CheckInvariants because
- even if a function can't provide the no-throw guarantee, it should still
- make sure that static data remains in a valid state.
- - typedef ::Loki::StaticChecker< ::Loki::CheckForNoThrow > CheckStaticForNoThrow;
- - typedef ::Loki::StaticChecker< ::Loki::CheckForNothing > CheckStaticInvariants;
- -# Construct a checker near the top of each member function - except in the
- validator member function. Pass the address of your validator function into
- the checker's constructor.
+ - But it should never throw an exception.
+ -# If the checker validates static functions within a class, add this line to
+ the class declaration.
+ - typedef ::Loki::CheckStaticFor CheckStaticFor;
+ -# Construct a checker near the top of each member function using one of
+ these lines:
+ - CheckStaticFor::NoThrow checker( &Host::StaticIsValid );
+ - CheckStaticFor::Invariants checker( &Host::StaticIsValid );
+ -# These guidelines can help you decide which exception policy to use within
+ each function.
- If the function never throws, then use the CheckForNoThrow policy.
- Otherwise use the CheckInvariants policy.
+ -# If the checker validates standalone functions, then just add one of these
+ lines at the top of the function. You may also want to write validation
+ functions which check pre-conditions and post-conditions of standalone
+ functions which you can pass into the checker as optional 2nd and 3rd
+ parameters.
+ - ::Loki::CheckStaticFor::NoThrow checker( &AllIsValid );
+ - ::Loki::CheckStaticFor::Invariants checker( &AllIsValid );
-# Recompile a debug version of your program, run it, and see if an assertion
fails.
*/
@@ -511,6 +574,24 @@
// ----------------------------------------------------------------------------
+/** @struct CheckStaticFor
+ This struct declares types of checkers used to validate standalone functions
+ and class static functions. All of Loki's exception-checking policies for
+ StaticChecker are named here as typedef's. If you write your own
+ exception policies for StaticChecker, you might want to also write a struct
+ similiar to CheckStaticFor to conveniently declare all your policies.
+ */
+struct CheckStaticFor
+{
+ // These lines declare checkers for static functions of a host class
+ // or for standalone functions outside any class or struct.
+ typedef StaticChecker< CheckStaticForNoThrow > NoThrow;
+ typedef StaticChecker< CheckStaticForNothing > Invariants;
+
+};
+
+// ----------------------------------------------------------------------------
+
}; // end namespace Loki
#endif
Modified: trunk/test/Checker/main.cpp
===================================================================
--- trunk/test/Checker/main.cpp 2009-03-17 18:21:12 UTC (rev 1011)
+++ trunk/test/Checker/main.cpp 2009-03-31 21:56:08 UTC (rev 1012)
@@ -92,16 +92,11 @@
/// This can be used to validate pre-conditions and post-conditions.
bool IsValidFull( void ) const;
- // These lines show how to declare checkers for non-static functions in a host class.
- typedef ::Loki::ContractChecker< Thingy, ::Loki::CheckForNoThrow > CheckForNoThrow;
- typedef ::Loki::ContractChecker< Thingy, ::Loki::CheckForNoChangeOrThrow > CheckForNoChangeOrThrow;
- typedef ::Loki::ContractChecker< Thingy, ::Loki::CheckForNoChange > CheckForNoChange;
- typedef ::Loki::ContractChecker< Thingy, ::Loki::CheckForEquality > CheckForEquality;
- typedef ::Loki::ContractChecker< Thingy, ::Loki::CheckForNothing > CheckInvariants;
+ // This shows how to declare checkers for non-static functions in a host class.
+ typedef ::Loki::CheckFor< Thingy > CheckFor;
- // These lines show how to declare checkers for static functions of a host class.
- typedef ::Loki::StaticChecker< ::Loki::CheckStaticForNoThrow > CheckStaticForNoThrow;
- typedef ::Loki::StaticChecker< ::Loki::CheckStaticForNothing > CheckStaticInvariants;
+ // This shows how to declare checkers for static functions of a host class.
+ typedef ::Loki::CheckStaticFor CheckStaticFor;
typedef ::std::vector< unsigned int > IntBlock;
@@ -120,7 +115,7 @@
// This example shows how static functions can use a no-throw checkers.
void Thingy::ChangeThat( void )
{
- CheckStaticForNoThrow checker( &Thingy::StaticIsValid );
+ CheckStaticFor::NoThrow checker( &Thingy::StaticIsValid );
(void)checker;
s_value--;
}
@@ -130,7 +125,7 @@
// This example shows how static functions can use an invariant checker.
unsigned int Thingy::GetThat( void )
{
- CheckStaticInvariants checker( &Thingy::StaticIsValid );
+ CheckStaticFor::Invariants checker( &Thingy::StaticIsValid );
(void)checker;
return s_value;
}
@@ -142,7 +137,7 @@
m_value( value ),
m_counts()
{
- CheckInvariants checker( this, &Thingy::IsValid );
+ CheckFor::Invariants checker( this, &Thingy::IsValid );
(void)checker;
}
@@ -152,7 +147,7 @@
m_value( that.m_value ),
m_counts( that.m_counts )
{
- CheckInvariants checker( this, &Thingy::IsValid );
+ CheckFor::Invariants checker( this, &Thingy::IsValid );
(void)checker;
}
@@ -160,7 +155,7 @@
Thingy & Thingy::operator = ( const Thingy & that )
{
- CheckInvariants checker( this, &Thingy::IsValid );
+ CheckFor::Invariants checker( this, &Thingy::IsValid );
(void)checker;
if ( &that != this )
{
@@ -184,9 +179,9 @@
// A swap function gets 2 checkers - one for this, and another for that.
void Thingy::Swap( Thingy & that )
{
- CheckInvariants checker1( this, &Thingy::IsValid );
+ CheckFor::Invariants checker1( this, &Thingy::IsValid );
(void)checker1;
- CheckInvariants checker2( &that, &Thingy::IsValid );
+ CheckFor::Invariants checker2( &that, &Thingy::IsValid );
(void)checker2;
const IntBlock counts( m_counts );
@@ -216,7 +211,7 @@
// This example shows how to use the no-throw checker.
unsigned int Thingy::GetValue( void ) const
{
- CheckForNoThrow checker( this, &Thingy::IsValid );
+ CheckFor::NoThrow checker( this, &Thingy::IsValid );
(void)checker;
return m_value;
}
@@ -226,7 +221,7 @@
// This example shows how to use the equality checker.
unsigned int Thingy::DoSomething( bool doThrow ) const
{
- CheckForEquality checker( this, &Thingy::IsValid );
+ CheckFor::Equality checker( this, &Thingy::IsValid );
(void)checker;
if ( doThrow )
throw ::std::logic_error( "Test Exception." );
@@ -238,7 +233,7 @@
// This example shows how to use the no-change checker.
void Thingy::DoSomethingElse( void ) const
{
- CheckForNoChange checker( this, &Thingy::IsValid );
+ CheckFor::NoChange checker( this, &Thingy::IsValid );
(void)checker;
}
@@ -250,7 +245,7 @@
// but does not need to check pre-conditions, so it passes in a nullptr for
// the pre-condition validator. Ths post-condition validator just makes sure
// the container has at least 1 element.
- CheckInvariants checker( this, &Thingy::IsValid, nullptr, &Thingy::IsValidFull );
+ CheckFor::Invariants checker( this, &Thingy::IsValid, nullptr, &Thingy::IsValidFull );
m_counts.push_back( count );
}
@@ -261,7 +256,7 @@
// This function's checker cares about class invariants and both the pre- and
// post-conditions, so it passes in pointers for all 3 validators. The pre-
// and post-conditions are both about making sure the container is not empty.
- CheckForNoChangeOrThrow checker( this, &Thingy::IsValid, &Thingy::IsValidFull, &Thingy::IsValidFull );
+ CheckFor::NoChangeOrThrow checker( this, &Thingy::IsValid, &Thingy::IsValidFull, &Thingy::IsValidFull );
if ( m_counts.size() <= index )
return 0;
const unsigned int count = m_counts[ index ];
@@ -276,7 +271,7 @@
// but does not need to check pre-conditions, so it passes in a nullptr for
// the pre-condition validator. Ths post-condition validator just makes sure
// the container has no elements.
- CheckForNoThrow checker( this, &Thingy::IsValid, nullptr, &Thingy::IsValidEmpty );
+ CheckFor::NoThrow checker( this, &Thingy::IsValid, nullptr, &Thingy::IsValidEmpty );
m_counts.clear();
}
@@ -328,16 +323,10 @@
// ----------------------------------------------------------------------------
-// These lines show how to declare checkers for standalone functions.
-typedef ::Loki::StaticChecker< ::Loki::CheckStaticForNoThrow > CheckStaticForNoThrow;
-typedef ::Loki::StaticChecker< ::Loki::CheckStaticForNothing > CheckStaticInvariants;
-
-// ----------------------------------------------------------------------------
-
void DoSomething( void )
{
// This example shows how to use a checker in a stand-alone function.
- CheckStaticForNoThrow checker( &AllIsValid );
+ ::Loki::CheckStaticFor::NoThrow checker( &AllIsValid );
(void)checker;
Thingy::ChangeThat();
}
@@ -355,6 +344,8 @@
int main( unsigned int argc, const char * const argv[] )
{
+ (void)argc;
+ (void)argv;
try
{
cout << "Just before call to ThrowTest." << endl;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jfb...@us...> - 2009-03-17 18:21:53
|
Revision: 1011
http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1011&view=rev
Author: jfbastien
Date: 2009-03-17 18:21:12 +0000 (Tue, 17 Mar 2009)
Log Message:
-----------
Bug 2690414: flex_string missing swap implementation
Modified Paths:
--------------
trunk/include/loki/flex/flex_string_shell.h
trunk/test/flex_string/main.cpp
Modified: trunk/include/loki/flex/flex_string_shell.h
===================================================================
--- trunk/include/loki/flex/flex_string_shell.h 2009-03-13 15:17:59 UTC (rev 1010)
+++ trunk/include/loki/flex/flex_string_shell.h 2009-03-17 18:21:12 UTC (rev 1011)
@@ -1305,8 +1305,12 @@
const flex_string<E, T, A, S>& rhs)
{ return !(lhs < rhs); }
-// subclause 21.3.7.8:
-//void swap(flex_string<E, T, A, S>& lhs, flex_string<E, T, A, S>& rhs); // to do
+template <typename E, class T, class A, class S>
+inline void swap(flex_string<E, T, A, S>& lhs, flex_string<E, T, A, S>& rhs)
+{
+ // 21.3.7.8
+ lhs.swap(rhs);
+}
template <typename E, class T, class A, class S>
std::basic_istream<typename flex_string<E, T, A, S>::value_type,
Modified: trunk/test/flex_string/main.cpp
===================================================================
--- trunk/test/flex_string/main.cpp 2009-03-13 15:17:59 UTC (rev 1010)
+++ trunk/test/flex_string/main.cpp 2009-03-17 18:21:12 UTC (rev 1011)
@@ -515,7 +515,7 @@
template<class String>
String swap_string_string()
{
- using std::swap;
+ // 21.3.7.8
String random1(RandomString<String>(MaxString<String>::value));
String random2(RandomString<String>(MaxString<String>::value));
swap(random1, random2);
@@ -525,7 +525,7 @@
template<class String>
String swap_string_string__self()
{
- using std::swap;
+ // 21.3.7.8
String random1(RandomString<String>(MaxString<String>::value));
swap(random1, random1);
return random1;
@@ -534,7 +534,7 @@
template<class String>
String swap_string_string__selfcopy()
{
- using std::swap;
+ // 21.3.7.8
String random1(RandomString<String>(MaxString<String>::value));
String copy(random1);
swap(random1, copy);
@@ -544,7 +544,7 @@
template<class String>
String swap_string_string__selfcopy2()
{
- using std::swap;
+ // 21.3.7.8
String random1(RandomString<String>(MaxString<String>::value));
String copy(random1);
swap(copy, random1);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jfb...@us...> - 2009-03-13 15:18:20
|
Revision: 1010
http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1010&view=rev
Author: jfbastien
Date: 2009-03-13 15:17:59 +0000 (Fri, 13 Mar 2009)
Log Message:
-----------
Copy/paste mistake.
Modified Paths:
--------------
trunk/test/flex_string/main.cpp
Modified: trunk/test/flex_string/main.cpp
===================================================================
--- trunk/test/flex_string/main.cpp 2009-03-13 13:54:51 UTC (rev 1009)
+++ trunk/test/flex_string/main.cpp 2009-03-13 15:17:59 UTC (rev 1010)
@@ -608,7 +608,7 @@
{
// 21.3.1
const typename String::size_type number = random(0, MaxString<String>::value);
- const typename String::size_type value = random('a', 'z');
+ const typename String::value_type value = random('a', 'z');
String result(number, value);
return result;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jfb...@us...> - 2009-03-13 13:55:09
|
Revision: 1009
http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1009&view=rev
Author: jfbastien
Date: 2009-03-13 13:54:51 +0000 (Fri, 13 Mar 2009)
Log Message:
-----------
Bug 2686155: flex_string is missing input_iterator methods
Modified Paths:
--------------
trunk/include/loki/flex/flex_string_shell.h
trunk/test/flex_string/main.cpp
Modified: trunk/include/loki/flex/flex_string_shell.h
===================================================================
--- trunk/include/loki/flex/flex_string_shell.h 2009-03-13 12:07:15 UTC (rev 1008)
+++ trunk/include/loki/flex/flex_string_shell.h 2009-03-13 13:54:51 UTC (rev 1009)
@@ -645,16 +645,16 @@
}
template <class InputIterator>
- void InsertImpl(iterator i1, iterator i2,
- InputIterator b, InputIterator e, std::input_iterator_tag)
+ void InsertImpl(iterator insertPosition,
+ InputIterator inputBegin, InputIterator inputEnd, std::input_iterator_tag)
{
- flex_string temp(begin(), i1);
- for (; b != e; ++b)
+ flex_string temporary(begin(), insertPosition);
+ for (; inputBegin != inputEnd; ++inputBegin)
{
- temp.push_back(*b);
+ temporary.push_back(*inputBegin);
}
- temp.append(i2, end());
- swap(temp);
+ temporary.append(insertPosition, end());
+ swap(temporary);
}
public:
Modified: trunk/test/flex_string/main.cpp
===================================================================
--- trunk/test/flex_string/main.cpp 2009-03-13 12:07:15 UTC (rev 1008)
+++ trunk/test/flex_string/main.cpp 2009-03-13 13:54:51 UTC (rev 1009)
@@ -36,6 +36,7 @@
#include <cstring>
#include <ctime>
#include <iostream>
+#include <iterator>
#include <typeinfo>
#include <sstream>
#include <utility>
@@ -621,6 +622,19 @@
return result;
}
+ template<class String>
+ String constructor_iterator_iterator__istream_iterator()
+ {
+ // 21.3.5
+ String random1(RandomString<String>(MaxString<String>::value));
+ typedef typename String::value_type value_type;
+ std::basic_stringstream<value_type, std::char_traits<value_type> > stream;
+ stream << random1;
+ std::istreambuf_iterator<value_type, std::char_traits<value_type> > begin(stream), end;
+ String result(begin, end);
+ return result;
+ }
+
// TODO: destructor
template<class String>
@@ -1052,6 +1066,20 @@
}
template<class String>
+ String append_iterator_iterator__istream_iterator()
+ {
+ // 21.3.5
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ typedef typename String::value_type value_type;
+ std::basic_stringstream<value_type, std::char_traits<value_type> > stream;
+ stream << random1;
+ std::istreambuf_iterator<value_type, std::char_traits<value_type> > begin(stream), end;
+ random2.append(begin, end);
+ return random2;
+ }
+
+ template<class String>
String push_back_char()
{
// 21.3.5
@@ -1246,6 +1274,20 @@
}
template<class String>
+ String assign_iterator_iterator__istream_iterator()
+ {
+ // 21.3.5
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ typedef typename String::value_type value_type;
+ std::basic_stringstream<value_type, std::char_traits<value_type> > stream;
+ stream << random1;
+ std::istreambuf_iterator<value_type, std::char_traits<value_type> > begin(stream), end;
+ random2.assign(begin, end);
+ return random2;
+ }
+
+ template<class String>
String insert_position_string()
{
// 21.3.5
@@ -1406,7 +1448,7 @@
}
template<class String>
- String insert_iterator_iterator()
+ String insert_iterator_iterator_iterator()
{
// 21.3.5
String random1(RandomString<String>(MaxString<String>::value));
@@ -1417,7 +1459,7 @@
}
template<class String>
- String insert_iterator_iterator__self()
+ String insert_iterator_iterator_iterator__self()
{
// 21.3.5
String random1(RandomString<String>(MaxString<String>::value));
@@ -1427,7 +1469,7 @@
}
template<class String>
- String insert_iterator_iterator__selfcopy()
+ String insert_iterator_iterator_iterator__selfcopy()
{
// 21.3.5
String random1(RandomString<String>(MaxString<String>::value));
@@ -1438,7 +1480,7 @@
}
template<class String>
- String insert_iterator_iterator__self_reverse()
+ String insert_iterator_iterator_iterator__self_reverse()
{
// 21.3.5
String random1(RandomString<String>(MaxString<String>::value));
@@ -1448,7 +1490,7 @@
}
template<class String>
- String insert_iterator_iterator__selfcopy_reverse()
+ String insert_iterator_iterator_iterator__selfcopy_reverse()
{
// 21.3.5
String random1(RandomString<String>(MaxString<String>::value));
@@ -1459,6 +1501,21 @@
}
template<class String>
+ String insert_iterator_iterator_iterator__istream_iterator()
+ {
+ // 21.3.5
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type position = random(0, random2.size());
+ typedef typename String::value_type value_type;
+ std::basic_stringstream<value_type, std::char_traits<value_type> > stream;
+ stream << random1;
+ std::istreambuf_iterator<value_type, std::char_traits<value_type> > begin(stream), end;
+ random2.insert(random2.begin() + position, begin, end);
+ return random2;
+ }
+
+ template<class String>
String erase_position_number()
{
// 21.3.5
@@ -1843,6 +1900,22 @@
}
template<class String>
+ String replace_iterator_iterator_iterator_iterator__istream_iterator()
+ {
+ // 21.3.5
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type position1 = random(0, random1.size());
+ const typename String::size_type position2 = random(position1, random1.size());
+ typedef typename String::value_type value_type;
+ std::basic_stringstream<value_type, std::char_traits<value_type> > stream;
+ stream << random2;
+ std::istreambuf_iterator<value_type, std::char_traits<value_type> > begin(stream), end;
+ random1.replace(random1.begin() + position1, random1.begin() + position2, begin, end);
+ return random1;
+ }
+
+ template<class String>
String copy_char_number_position()
{
// 21.3.5
@@ -2726,6 +2799,7 @@
ADD_TEST(constructor_cstr_number);
ADD_TEST(constructor_number_char);
ADD_TEST(constructor_iterator_iterator);
+ ADD_TEST(constructor_iterator_iterator__istream_iterator);
ADD_TEST(operator_equal_string);
ADD_TEST(operator_equal_string__self);
ADD_TEST(operator_equal_string__selfCopy);
@@ -2765,6 +2839,7 @@
ADD_TEST(append_iterator_iterator__selfcopy);
ADD_TEST(append_iterator_iterator__self_reverse);
ADD_TEST(append_iterator_iterator__selfcopy_reverse);
+ ADD_TEST(append_iterator_iterator__istream_iterator);
ADD_TEST(push_back_char);
ADD_TEST(assign_string);
ADD_TEST(assign_string__self);
@@ -2784,6 +2859,7 @@
ADD_TEST(assign_iterator_iterator__selfcopy);
ADD_TEST(assign_iterator_iterator__self_reverse);
ADD_TEST(assign_iterator_iterator__selfcopy_reverse);
+ ADD_TEST(assign_iterator_iterator__istream_iterator);
ADD_TEST(insert_position_string);
ADD_TEST(insert_position_string__self);
ADD_TEST(insert_position_string__selfcopy);
@@ -2798,11 +2874,12 @@
ADD_TEST(insert_position_cstr__selfcopy);
ADD_TEST(insert_iterator_char);
ADD_TEST(insert_position_number_char);
- ADD_TEST(insert_iterator_iterator);
- ADD_TEST(insert_iterator_iterator__self);
- ADD_TEST(insert_iterator_iterator__selfcopy);
- ADD_TEST(insert_iterator_iterator__self_reverse);
- ADD_TEST(insert_iterator_iterator__selfcopy_reverse);
+ ADD_TEST(insert_iterator_iterator_iterator);
+ ADD_TEST(insert_iterator_iterator_iterator__self);
+ ADD_TEST(insert_iterator_iterator_iterator__selfcopy);
+ ADD_TEST(insert_iterator_iterator_iterator__self_reverse);
+ ADD_TEST(insert_iterator_iterator_iterator__selfcopy_reverse);
+ ADD_TEST(insert_iterator_iterator_iterator__istream_iterator);
ADD_TEST(erase_position_number);
ADD_TEST(erase_iterator);
ADD_TEST(erase_iterator_iterator);
@@ -2832,6 +2909,7 @@
ADD_TEST(replace_iterator_iterator_iterator_iterator);
ADD_TEST(replace_iterator_iterator_iterator_iterator__self);
ADD_TEST(replace_iterator_iterator_iterator_iterator__selfcopy);
+ ADD_TEST(replace_iterator_iterator_iterator_iterator__istream_iterator);
ADD_TEST(copy_char_number_position);
ADD_TEST(swap);
ADD_TEST(swap__self);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jfb...@us...> - 2009-03-13 12:07:20
|
Revision: 1008
http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1008&view=rev
Author: jfbastien
Date: 2009-03-13 12:07:15 +0000 (Fri, 13 Mar 2009)
Log Message:
-----------
Cosmetic: remove trailing spaces.
Modified Paths:
--------------
trunk/include/loki/flex/allocatorstringstorage.h
trunk/include/loki/flex/cowstringopt.h
trunk/include/loki/flex/simplestringstorage.h
trunk/include/loki/flex/vectorstringstorage.h
Modified: trunk/include/loki/flex/allocatorstringstorage.h
===================================================================
--- trunk/include/loki/flex/allocatorstringstorage.h 2009-03-13 11:39:47 UTC (rev 1007)
+++ trunk/include/loki/flex/allocatorstringstorage.h 2009-03-13 12:07:15 UTC (rev 1008)
@@ -26,7 +26,7 @@
typedef @ const_iterator;
typedef A allocator_type;
typedef @ size_type;
-
+
StoragePolicy(const StoragePolicy& s);
StoragePolicy(const A&);
StoragePolicy(const E* s, size_type len, const A&);
@@ -37,7 +37,7 @@
const_iterator begin() const;
iterator end();
const_iterator end() const;
-
+
size_type size() const;
size_type max_size() const;
size_type capacity() const;
@@ -50,10 +50,10 @@
void resize(size_type newSize, E fill);
void swap(StoragePolicy& rhs);
-
+
const E* c_str() const;
const E* data() const;
-
+
A get_allocator() const;
};
////////////////////////////////////////////////////////////////////////////////
@@ -82,7 +82,7 @@
void* Alloc(size_type sz, const void* p = 0)
{
- return A::allocate(1 + (sz - 1) / sizeof(E),
+ return A::allocate(1 + (sz - 1) / sizeof(E),
static_cast<const char*>(p));
}
@@ -118,43 +118,43 @@
pData_->pEndOfMem_ = pData_->buffer_ + cap;
}
}
-
+
public:
typedef E value_type;
typedef A allocator_type;
typedef typename A::pointer iterator;
typedef typename A::const_pointer const_iterator;
- AllocatorStringStorage()
+ AllocatorStringStorage()
: A(), pData_(0)
{
}
- AllocatorStringStorage(const AllocatorStringStorage& rhs)
+ AllocatorStringStorage(const AllocatorStringStorage& rhs)
: A(rhs.get_allocator())
{
const size_type sz = rhs.size();
Init(sz, sz);
if (sz) flex_string_details::pod_copy(rhs.begin(), rhs.end(), begin());
}
-
- AllocatorStringStorage(const AllocatorStringStorage& s,
- flex_string_details::Shallow)
+
+ AllocatorStringStorage(const AllocatorStringStorage& s,
+ flex_string_details::Shallow)
: A(s.get_allocator())
{
pData_ = s.pData_;
}
-
+
AllocatorStringStorage(const A& a) : A(a)
- {
+ {
pData_ = const_cast<Data*>(
&SimpleStringStorage<E, A>::emptyString_);
}
-
+
AllocatorStringStorage(const E* s, size_type len, const A& a)
: A(a)
{
- Init(len, len);
+ Init(len, len);
flex_string_details::pod_copy(s, s + len, begin());
}
@@ -164,7 +164,7 @@
Init(len, len);
flex_string_details::pod_fill(&*begin(), &*end(), c);
}
-
+
AllocatorStringStorage& operator=(const AllocatorStringStorage& rhs)
{
const size_type sz = rhs.size();
@@ -173,28 +173,28 @@
pData_->pEnd_ = &*begin() + rhs.size();
return *this;
}
-
+
~AllocatorStringStorage()
{
if (capacity())
{
- Free(pData_,
+ Free(pData_,
sizeof(Data) + capacity() * sizeof(E));
}
}
-
+
iterator begin()
{ return pData_->buffer_; }
-
+
const_iterator begin() const
{ return pData_->buffer_; }
-
+
iterator end()
{ return pData_->pEnd_; }
-
+
const_iterator end() const
{ return pData_->pEnd_; }
-
+
size_type size() const
{ return size_type(end() - begin()); }
@@ -209,7 +209,7 @@
reserve(n);
iterator newEnd = begin() + n;
iterator oldEnd = end();
- if (newEnd > oldEnd)
+ if (newEnd > oldEnd)
{
// Copy the characters
flex_string_details::pod_fill(oldEnd, newEnd, c);
@@ -221,23 +221,23 @@
{
if (res_arg <= capacity())
{
- // @@@ shrink to fit here
+ // @@@ shrink to fit here
return;
}
-
+
A& myAlloc = *this;
AllocatorStringStorage newStr(myAlloc);
newStr.Init(size(), res_arg);
-
+
flex_string_details::pod_copy(begin(), end(), newStr.begin());
-
+
swap(newStr);
}
template <class ForwardIterator>
void append(ForwardIterator b, ForwardIterator e)
{
- const size_type
+ const size_type
sz = std::distance(b, e),
neededCapacity = size() + sz;
@@ -251,26 +251,26 @@
std::copy(b, e, end());
pData_->pEnd_ += sz;
}
-
+
void swap(AllocatorStringStorage& rhs)
{
// @@@ The following line is commented due to a bug in MSVC
//std::swap(lhsAlloc, rhsAlloc);
std::swap(pData_, rhs.pData_);
}
-
+
const E* c_str() const
- {
- if (pData_ != &SimpleStringStorage<E, A>::emptyString_)
+ {
+ if (pData_ != &SimpleStringStorage<E, A>::emptyString_)
{
*pData_->pEnd_ = E();
}
- return &*begin();
+ return &*begin();
}
const E* data() const
{ return &*begin(); }
-
+
A get_allocator() const
{ return *this; }
};
Modified: trunk/include/loki/flex/cowstringopt.h
===================================================================
--- trunk/include/loki/flex/cowstringopt.h 2009-03-13 11:39:47 UTC (rev 1007)
+++ trunk/include/loki/flex/cowstringopt.h 2009-03-13 12:07:15 UTC (rev 1008)
@@ -32,7 +32,7 @@
typedef @ const_iterator;
typedef A allocator_type;
typedef @ size_type;
-
+
StoragePolicy(const StoragePolicy& s);
StoragePolicy(const A&);
StoragePolicy(const E* s, size_type len, const A&);
@@ -43,7 +43,7 @@
const_iterator begin() const;
iterator end();
const_iterator end() const;
-
+
size_type size() const;
size_type max_size() const;
size_type capacity() const;
@@ -51,17 +51,17 @@
void reserve(size_type res_arg);
void append(const E* s, size_type sz);
-
+
template <class InputIterator>
void append(InputIterator b, InputIterator e);
void resize(size_type newSize, E fill);
void swap(StoragePolicy& rhs);
-
+
const E* c_str() const;
const E* data() const;
-
+
A get_allocator() const;
};
////////////////////////////////////////////////////////////////////////////////
@@ -94,7 +94,7 @@
typedef typename Storage::allocator_type allocator_type;
typedef typename allocator_type::size_type size_type;
typedef typename Storage::reference reference;
-
+
private:
union
{
@@ -112,14 +112,14 @@
assert(*d.begin() > 0);
return *d.begin();
}
-
+
RefCountType& Refs()
{
Storage& d = Data();
assert(d.size() > 0);
return reinterpret_cast<RefCountType&>(*d.begin());
}
-
+
void MakeUnique() const
{
assert(GetRefs() >= 1);
@@ -134,7 +134,7 @@
--(*Data().begin()); // Harmut Kaiser fix:
// decrement the use count of the remaining object
new(buf_) Storage(
- *new(temp.buf_) Storage(Data()),
+ *new(temp.buf_) Storage(Data()),
flex_string_details::Shallow());
*Data().begin() = 1;
}
@@ -155,12 +155,12 @@
}
assert(Data().size() > 0);
}
-
+
CowStringOpt(const allocator_type& a)
{
new(buf_) Storage(1, 1, a);
}
-
+
CowStringOpt(const E* s, size_type len, const allocator_type& a)
{
// Warning - MSVC's debugger has trouble tracing through the code below.
@@ -177,7 +177,7 @@
new(buf_) Storage(len + 1, c, a);
Refs() = 1;
}
-
+
CowStringOpt& operator=(const CowStringOpt& rhs)
{
CowStringOpt(rhs).swap(*this);
@@ -194,26 +194,26 @@
{
assert(Data().size() > 0);
MakeUnique();
- return Data().begin() + 1;
+ return Data().begin() + 1;
}
-
+
const_iterator begin() const
{
assert(Data().size() > 0);
- return Data().begin() + 1;
+ return Data().begin() + 1;
}
-
+
iterator end()
{
MakeUnique();
- return Data().end();
+ return Data().end();
}
-
+
const_iterator end() const
{
- return Data().end();
+ return Data().end();
}
-
+
size_type size() const
{
assert(Data().size() > 0);
@@ -221,13 +221,13 @@
}
size_type max_size() const
- {
+ {
assert(Data().max_size() > 0);
return Data().max_size() - 1;
}
size_type capacity() const
- {
+ {
assert(Data().capacity() > 0);
return Data().capacity() - 1;
}
@@ -245,33 +245,33 @@
MakeUnique();
Data().append(b, e);
}
-
+
void reserve(size_type res_arg)
{
if (capacity() > res_arg) return;
MakeUnique();
Data().reserve(res_arg + 1);
}
-
+
void swap(CowStringOpt& rhs)
{
Data().swap(rhs.Data());
}
-
+
const E* c_str() const
- {
+ {
assert(Data().size() > 0);
return Data().c_str() + 1;
}
const E* data() const
- {
+ {
assert(Data().size() > 0);
return Data().data() + 1;
}
-
+
allocator_type get_allocator() const
- {
+ {
return Data().get_allocator();
}
};
Modified: trunk/include/loki/flex/simplestringstorage.h
===================================================================
--- trunk/include/loki/flex/simplestringstorage.h 2009-03-13 11:39:47 UTC (rev 1007)
+++ trunk/include/loki/flex/simplestringstorage.h 2009-03-13 12:07:15 UTC (rev 1008)
@@ -26,7 +26,7 @@
typedef @ const_iterator;
typedef A allocator_type;
typedef @ size_type;
-
+
StoragePolicy(const StoragePolicy& s);
StoragePolicy(const A&);
StoragePolicy(const E* s, size_type len, const A&);
@@ -37,7 +37,7 @@
const_iterator begin() const;
iterator end();
const_iterator end() const;
-
+
size_type size() const;
size_type max_size() const;
size_type capacity() const;
@@ -50,10 +50,10 @@
void resize(size_type newSize, E fill);
void swap(StoragePolicy& rhs);
-
+
const E* c_str() const;
const E* data() const;
-
+
A get_allocator() const;
};
////////////////////////////////////////////////////////////////////////////////
@@ -86,7 +86,7 @@
E buffer_[1];
};
static const Data emptyString_;
-
+
typedef typename A::size_type size_type;
private:
@@ -95,14 +95,14 @@
void Init(size_type size, size_type capacity)
{
assert(size <= capacity);
- if (capacity == 0)
+ if (capacity == 0)
{
pData_ = const_cast<Data*>(&emptyString_);
}
else
{
- // 11-17-2000: comment added:
- // No need to allocate (capacity + 1) to
+ // 11-17-2000: comment added:
+ // No need to allocate (capacity + 1) to
// accommodate the terminating 0, because Data already
// has one one character in there
pData_ = static_cast<Data*>(
@@ -112,12 +112,12 @@
pData_->pEndOfMem_ = pData_->buffer_ + capacity;
}
}
-
+
private:
// Warning - this doesn't initialize pData_. Used in reserve()
SimpleStringStorage()
{ }
-
+
public:
typedef E value_type;
typedef E* iterator;
@@ -125,23 +125,23 @@
typedef A allocator_type;
typedef typename A::reference reference;
-
- SimpleStringStorage(const SimpleStringStorage& rhs)
+
+ SimpleStringStorage(const SimpleStringStorage& rhs)
{
const size_type sz = rhs.size();
Init(sz, sz);
if (sz) flex_string_details::pod_copy(rhs.begin(), rhs.end(), begin());
}
-
- SimpleStringStorage(const SimpleStringStorage& s,
- flex_string_details::Shallow)
+
+ SimpleStringStorage(const SimpleStringStorage& s,
+ flex_string_details::Shallow)
: pData_(s.pData_)
{
}
-
+
SimpleStringStorage(const A&)
{ pData_ = const_cast<Data*>(&emptyString_); }
-
+
SimpleStringStorage(const E* s, size_type len, const A&)
{
Init(len, len);
@@ -153,7 +153,7 @@
Init(len, len);
flex_string_details::pod_fill(begin(), end(), c);
}
-
+
SimpleStringStorage& operator=(const SimpleStringStorage& rhs)
{
const size_type sz = rhs.size();
@@ -171,16 +171,16 @@
iterator begin()
{ return pData_->buffer_; }
-
+
const_iterator begin() const
{ return pData_->buffer_; }
-
+
iterator end()
{ return pData_->pEnd_; }
-
+
const_iterator end() const
{ return pData_->pEnd_; }
-
+
size_type size() const
{ return pData_->pEnd_ - pData_->buffer_; }
@@ -198,7 +198,7 @@
return;
}
- if (pData_ == &emptyString_)
+ if (pData_ == &emptyString_)
{
Init(0, res_arg);
}
@@ -206,10 +206,10 @@
{
const size_type sz = size();
- void* p = realloc(pData_,
+ void* p = realloc(pData_,
sizeof(Data) + res_arg * sizeof(E));
if (!p) throw std::bad_alloc();
-
+
if (p != pData_)
{
pData_ = static_cast<Data*>(p);
@@ -222,7 +222,7 @@
template <class InputIterator>
void append(InputIterator b, InputIterator e)
{
- const size_type
+ const size_type
sz = std::distance(b, e),
neededCapacity = size() + sz;
if (capacity() < neededCapacity)
@@ -235,7 +235,7 @@
std::copy(b, e, end());
pData_->pEnd_ += sz;
}
-
+
void resize(size_type newSize, E fill)
{
const int delta = int(newSize - size());
@@ -243,7 +243,7 @@
if (delta > 0)
{
- if (newSize > capacity())
+ if (newSize > capacity())
{
reserve(newSize);
}
@@ -257,16 +257,16 @@
{
std::swap(pData_, rhs.pData_);
}
-
+
const E* c_str() const
{
if (pData_ != &emptyString_) *pData_->pEnd_ = E();
- return pData_->buffer_;
+ return pData_->buffer_;
}
const E* data() const
{ return pData_->buffer_; }
-
+
A get_allocator() const
{ return A(); }
};
@@ -274,9 +274,9 @@
template <typename E, class A>
const typename SimpleStringStorage<E, A>::Data
SimpleStringStorage<E, A>::emptyString_;
-//{
-// const_cast<E*>(SimpleStringStorage<E, A>::emptyString_.buffer_),
-// const_cast<E*>(SimpleStringStorage<E, A>::emptyString_.buffer_),
+//{
+// const_cast<E*>(SimpleStringStorage<E, A>::emptyString_.buffer_),
+// const_cast<E*>(SimpleStringStorage<E, A>::emptyString_.buffer_),
// { E() }
//};
Modified: trunk/include/loki/flex/vectorstringstorage.h
===================================================================
--- trunk/include/loki/flex/vectorstringstorage.h 2009-03-13 11:39:47 UTC (rev 1007)
+++ trunk/include/loki/flex/vectorstringstorage.h 2009-03-13 12:07:15 UTC (rev 1008)
@@ -26,7 +26,7 @@
typedef @ const_iterator;
typedef A allocator_type;
typedef @ size_type;
-
+
StoragePolicy(const StoragePolicy& s);
StoragePolicy(const A&);
StoragePolicy(const E* s, size_type len, const A&);
@@ -37,7 +37,7 @@
const_iterator begin() const;
iterator end();
const_iterator end() const;
-
+
size_type size() const;
size_type max_size() const;
size_type capacity() const;
@@ -45,17 +45,17 @@
void reserve(size_type res_arg);
void append(const E* s, size_type sz);
-
+
template <class InputIterator>
void append(InputIterator b, InputIterator e);
void resize(size_type newSize, E fill);
void swap(StoragePolicy& rhs);
-
+
const E* c_str() const;
const E* data() const;
-
+
A get_allocator() const;
};
////////////////////////////////////////////////////////////////////////////////
@@ -87,13 +87,13 @@
typedef A allocator_type;
typedef typename A::size_type size_type;
typedef typename A::reference reference;
-
+
VectorStringStorage(const VectorStringStorage& s) : base(s)
{ }
-
+
VectorStringStorage(const A& a) : base(1, value_type(), a)
{ }
-
+
VectorStringStorage(const value_type* s, size_type len, const A& a)
: base(a)
{
@@ -109,26 +109,26 @@
// Terminating zero
base::back() = value_type();
}
-
+
VectorStringStorage& operator=(const VectorStringStorage& rhs)
{
base& v = *this;
v = rhs;
return *this;
}
-
+
iterator begin()
{ return base::begin(); }
-
+
const_iterator begin() const
{ return base::begin(); }
-
+
iterator end()
{ return base::end() - 1; }
-
+
const_iterator end() const
{ return base::end() - 1; }
-
+
size_type size() const
{ return base::size() - 1; }
@@ -139,11 +139,11 @@
{ return base::capacity() - 1; }
void reserve(size_type res_arg)
- {
+ {
assert(res_arg < max_size());
- base::reserve(res_arg + 1);
+ base::reserve(res_arg + 1);
}
-
+
template <class ForwardIterator>
void append(ForwardIterator b, ForwardIterator e)
{
@@ -178,13 +178,13 @@
void swap(VectorStringStorage& rhs)
{ base::swap(rhs); }
-
+
const E* c_str() const
{ return &*begin(); }
const E* data() const
{ return &*begin(); }
-
+
A get_allocator() const
{ return base::get_allocator(); }
};
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jfb...@us...> - 2009-03-13 11:39:52
|
Revision: 1007
http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1007&view=rev
Author: jfbastien
Date: 2009-03-13 11:39:47 +0000 (Fri, 13 Mar 2009)
Log Message:
-----------
Bug 2665120: flex_string fatal error assigning big string to small
Modified Paths:
--------------
trunk/include/loki/flex/smallstringopt.h
Modified: trunk/include/loki/flex/smallstringopt.h
===================================================================
--- trunk/include/loki/flex/smallstringopt.h 2009-03-12 12:28:58 UTC (rev 1006)
+++ trunk/include/loki/flex/smallstringopt.h 2009-03-13 11:39:47 UTC (rev 1007)
@@ -220,15 +220,7 @@
new(this) SmallStringOpt(rhs);
} else {
SmallStringOpt copy(rhs);
- if (Small()) {
- // no need to swap, just destructively read copy into this
- // ugly but efficient again
- memcpy(this, ©, sizeof(*this));
- copy.buf_[maxSmallString] = maxSmallString; // clear the copy
- } else {
- // Use the swap trick
- copy.swap(*this);
- }
+ copy.swap(*this);
}
}
return *this;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jfb...@us...> - 2009-03-12 12:29:05
|
Revision: 1006
http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1006&view=rev
Author: jfbastien
Date: 2009-03-12 12:28:58 +0000 (Thu, 12 Mar 2009)
Log Message:
-----------
Bug 2684989: flex_string insert char fails with SmallStringOpt
Modified Paths:
--------------
trunk/include/loki/flex/flex_string_shell.h
Modified: trunk/include/loki/flex/flex_string_shell.h
===================================================================
--- trunk/include/loki/flex/flex_string_shell.h 2009-03-11 17:58:49 UTC (rev 1005)
+++ trunk/include/loki/flex/flex_string_shell.h 2009-03-12 12:28:58 UTC (rev 1006)
@@ -548,29 +548,27 @@
Invariant checker(*this);
(void) checker;
assert(begin() <= p && p <= end());
- if (capacity() - size() < n)
+ const size_type insertOffset(p - begin());
+ const size_type originalSize(size());
+ if(n < originalSize - insertOffset)
{
- const size_type sz = p - begin();
- reserve(size() + n);
- p = begin() + sz;
+ // The new characters fit within the original string.
+ // The characters that are pushed back need to be moved because they're aliased.
+ // The appended characters will all be overwritten by the move.
+ append(n, value_type(0));
+ value_type * begin(&*begin());
+ flex_string_details::pod_move(begin + insertOffset, begin + originalSize, begin + insertOffset + n);
+ std::fill(begin + insertOffset, begin + insertOffset + n, c);
}
- const iterator oldEnd = end();
- //if (p + n < oldEnd) // replaced because of crash (pk)
- if( n < size_type(oldEnd - p))
- {
- append(oldEnd - n, oldEnd);
- //std::copy(
- // reverse_iterator(oldEnd - n),
- // reverse_iterator(p),
- // reverse_iterator(oldEnd));
- flex_string_details::pod_move(&*p, &*oldEnd - n, &*p + n);
- std::fill(p, p + n, c);
- }
else
{
- append(n - (end() - p), c);
- append(p, oldEnd);
- std::fill(p, oldEnd, c);
+ // The new characters exceed the original string.
+ // The characters that are pushed back can simply be copied since they aren't aliased.
+ // The appended characters will partly be overwritten by the copy.
+ append(n, c);
+ value_type * begin(&*begin());
+ flex_string_details::pod_copy(begin + insertOffset, begin + originalSize, begin + insertOffset + n);
+ std::fill(begin + insertOffset, begin + originalSize, c);
}
return *this;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jfb...@us...> - 2009-03-11 17:59:00
|
Revision: 1005
http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1005&view=rev
Author: jfbastien
Date: 2009-03-11 17:58:49 +0000 (Wed, 11 Mar 2009)
Log Message:
-----------
Bug 2679853: flex_string cannot insert from current string.
Modified Paths:
--------------
trunk/include/loki/flex/flex_string_shell.h
Modified: trunk/include/loki/flex/flex_string_shell.h
===================================================================
--- trunk/include/loki/flex/flex_string_shell.h 2009-03-10 19:58:26 UTC (rev 1004)
+++ trunk/include/loki/flex/flex_string_shell.h 2009-03-11 17:58:49 UTC (rev 1005)
@@ -388,8 +388,7 @@
{
Invariant checker(*this);
(void) checker;
- static std::less_equal<const value_type*> le;
- if (le(&*begin(), s) && le(s, &*end())) // aliasing
+ if (IsAliasedRange(s, s + n))
{
const size_type offset = s - &*begin();
Storage::reserve(size() + n);
@@ -501,6 +500,46 @@
}
private:
+
+ // Care must be taken when dereferencing some iterator types.
+ //
+ // Users can implement this function in their namespace if their storage uses a special iterator type,
+ // the function will be found through ADL.
+ template<class Iterator>
+ const typename std::iterator_traits<Iterator>::value_type * DereferenceValidIterator(Iterator it) const
+ {
+ return &*it;
+ }
+
+ // Care must be taken when dereferencing a reverse iterators, hence this special case.
+ // This isn't in the std namespace so as not to pollute it or create name clashes.
+ template<typename Iterator>
+ const typename std::iterator_traits<Iterator>::value_type * DereferenceValidIterator(
+ std::reverse_iterator<Iterator> it) const
+ {
+ return &*--it;
+ }
+
+ // Determine if the range aliases the current string.
+ //
+ // This method cannot be const because calling begin/end on copy-on-write implementations must have side effects.
+ // A const version wouldn't make the string unique through this call.
+ template<class Iterator>
+ bool IsAliasedRange(Iterator beginIterator, Iterator endIterator)
+ {
+ if(!empty() && beginIterator != endIterator)
+ {
+ typedef const typename std::iterator_traits<Iterator>::value_type * pointer;
+ pointer myBegin(&*begin());
+ pointer myEnd(&*begin() + size());
+ pointer rangeBegin(DereferenceValidIterator(beginIterator));
+ const std::less_equal<pointer> less_equal = std::less_equal<pointer>();
+ if(less_equal(myBegin, rangeBegin) && less_equal(rangeBegin, myEnd))
+ return true;
+ }
+ return false;
+ }
+
template <int i> class Selector {};
flex_string& InsertImplDiscr(iterator p,
@@ -508,7 +547,7 @@
{
Invariant checker(*this);
(void) checker;
- assert(p >= begin() && p <= end());
+ assert(begin() <= p && p <= end());
if (capacity() - size() < n)
{
const size_type sz = p - begin();
@@ -549,10 +588,24 @@
void InsertImpl(iterator i,
FwdIterator s1, FwdIterator s2, std::forward_iterator_tag)
{
- // TODO: there is a bug in this method when the range to insert is inside the current range. See bug #2679853.
+ if(s1 == s2)
+ {
+ // Insert an empty range.
+ return;
+ }
+ if(IsAliasedRange(s1, s2))
+ {
+ // The source range is contained in the current string, copy it and recurse.
+ const flex_string temporary(s1, s2);
+ InsertImpl(i, temporary.begin(), temporary.end(),
+ typename std::iterator_traits<FwdIterator>::iterator_category());
+ return;
+ }
+
Invariant checker(*this);
(void) checker;
+
const size_type pos = i - begin();
const typename std::iterator_traits<FwdIterator>::difference_type n2 =
std::distance(s1, s2);
@@ -564,10 +617,8 @@
capacity() - size();
if (maxn2 < n2)
{
- // realloc the string
- static const std::less_equal<const value_type*> le =
- std::less_equal<const value_type*>();
- assert(!(le(&*begin(), &*s1) && le(&*s1, &*end())));
+ // Reallocate the string.
+ assert(!IsAliasedRange(s1, s2));
reserve(size() + n2);
i = begin() + pos;
}
@@ -670,8 +721,7 @@
return replace(b, b + n1, s1, s1 + n2);
using namespace flex_string_details;
const int delta = int(n2 - n1);
- static const std::less_equal<const value_type*> le;
- const bool aliased = le(&*begin(), s1) && le(s1, &*end());
+ const bool aliased = IsAliasedRange(s1, s1 + n2);
// From here on we're dealing with an aliased replace
if (delta <= 0)
@@ -811,33 +861,25 @@
std::distance(s1, s2);
assert(n2 >= 0);
- // Make sure the replacement isn't empty.
- if(0 != n2)
+ if (IsAliasedRange(s1, s2))
{
- // Handle aliased replace
- static const std::less_equal<const value_type*> le =
- std::less_equal<const value_type*>();
- const bool aliased = le(&*begin(), &*s1) && le(&*s1, &*end());
- if (aliased /* && capacity() < size() - n1 + n2 */)
- {
- // Aliased replace, copy to new string
- flex_string temp;
- temp.reserve(size() - n1 + n2);
- temp.append(begin(), i1).append(s1, s2).append(i2, end());
- swap(temp);
- return;
- }
+ // Aliased replace, copy to new string.
+ flex_string temporary;
+ temporary.reserve(size() - n1 + n2);
+ temporary.append(begin(), i1).append(s1, s2).append(i2, end());
+ swap(temporary);
+ return;
}
if (n1 > n2)
{
- // shrinks
+ // Shrinks.
std::copy(s1, s2, i1);
erase(i1 + n2, i2);
}
else
{
- // grows
+ // Grows.
flex_string_details::copy_n(s1, n1, i1);
std::advance(s1, n1);
insert(i2, s1, s2);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jfb...@us...> - 2009-03-10 19:58:31
|
Revision: 1004
http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1004&view=rev
Author: jfbastien
Date: 2009-03-10 19:58:26 +0000 (Tue, 10 Mar 2009)
Log Message:
-----------
Add note on bug #2679853.
Modified Paths:
--------------
trunk/include/loki/flex/flex_string_shell.h
Modified: trunk/include/loki/flex/flex_string_shell.h
===================================================================
--- trunk/include/loki/flex/flex_string_shell.h 2009-03-10 19:55:59 UTC (rev 1003)
+++ trunk/include/loki/flex/flex_string_shell.h 2009-03-10 19:58:26 UTC (rev 1004)
@@ -47,22 +47,22 @@
//typedef std::ptrdiff_t difference_type;
typedef int difference_type;
- template <class U>
+ template <class U>
struct rebind { typedef mallocator<U> other; };
mallocator() {}
mallocator(const mallocator&) {}
- //template <class U>
+ //template <class U>
//mallocator(const mallocator<U>&) {}
~mallocator() {}
pointer address(reference x) const { return &x; }
- const_pointer address(const_reference x) const
- {
+ const_pointer address(const_reference x) const
+ {
return x;
}
- pointer allocate(size_type n, const_pointer = 0)
+ pointer allocate(size_type n, const_pointer = 0)
{
using namespace std;
void* p = malloc(n * sizeof(T));
@@ -70,25 +70,25 @@
return static_cast<pointer>(p);
}
- void deallocate(pointer p, size_type)
- {
+ void deallocate(pointer p, size_type)
+ {
using namespace std;
- free(p);
+ free(p);
}
- size_type max_size() const
- {
+ size_type max_size() const
+ {
return static_cast<size_type>(-1) / sizeof(T);
}
- void construct(pointer p, const value_type& x)
- {
- new(p) value_type(x);
+ void construct(pointer p, const value_type& x)
+ {
+ new(p) value_type(x);
}
- void destroy(pointer p)
- {
- p->~value_type();
+ void destroy(pointer p)
+ {
+ p->~value_type();
}
private:
@@ -101,18 +101,18 @@
typedef void* pointer;
typedef const void* const_pointer;
- template <class U>
+ template <class U>
struct rebind { typedef mallocator<U> other; };
};
template <class T>
-inline bool operator==(const mallocator<T>&,
+inline bool operator==(const mallocator<T>&,
const mallocator<T>&) {
return true;
}
template <class T>
-inline bool operator!=(const mallocator<T>&,
+inline bool operator!=(const mallocator<T>&,
const mallocator<T>&) {
return false;
}
@@ -120,7 +120,7 @@
template <class Allocator>
typename Allocator::pointer Reallocate(
Allocator& alloc,
- typename Allocator::pointer p,
+ typename Allocator::pointer p,
typename Allocator::size_type oldObjCount,
typename Allocator::size_type newObjCount,
void*)
@@ -131,7 +131,7 @@
template <class Allocator>
typename Allocator::pointer Reallocate(
Allocator& alloc,
- typename Allocator::pointer p,
+ typename Allocator::pointer p,
typename Allocator::size_type oldObjCount,
typename Allocator::size_type newObjCount,
mallocator<void>*)
@@ -142,8 +142,8 @@
////////////////////////////////////////////////////////////////////////////////
// class template flex_string
-// a std::basic_string compatible implementation
-// Uses a Storage policy
+// a std::basic_string compatible implementation
+// Uses a Storage policy
////////////////////////////////////////////////////////////////////////////////
template <typename E,
@@ -184,12 +184,12 @@
private:
const flex_string& s_;
#else
- Invariant(const flex_string&) {}
+ Invariant(const flex_string&) {}
#endif
private:
Invariant& operator=(const Invariant&);
};
-
+
public:
// types
typedef T traits_type;
@@ -197,12 +197,12 @@
typedef A allocator_type;
typedef typename A::size_type size_type;
typedef typename A::difference_type difference_type;
-
+
typedef typename Storage::reference reference;
typedef typename A::const_reference const_reference;
typedef typename A::pointer pointer;
typedef typename A::const_pointer const_pointer;
-
+
typedef typename Storage::iterator iterator;
typedef typename Storage::const_iterator const_iterator;
typedef std::reverse_iterator<iterator
@@ -212,7 +212,7 @@
> reverse_iterator;
typedef std::reverse_iterator<const_iterator
#ifdef NO_ITERATOR_TRAITS
- , const value_type
+ , const value_type
#endif
> const_reverse_iterator;
@@ -225,32 +225,32 @@
{ return lhs > rhs ? lhs : rhs; }
static void Procust(size_type& n, size_type nmax)
{ if (n > nmax) n = nmax; }
-
-public:
+
+public:
// 21.3.1 construct/copy/destroy
explicit flex_string(const A& a = A())
- : Storage(a)
+ : Storage(a)
{}
-
+
flex_string(const flex_string& str)
- : Storage(str)
+ : Storage(str)
{}
-
- flex_string(const flex_string& str, size_type pos,
+
+ flex_string(const flex_string& str, size_type pos,
size_type n = npos, const A& a = A())
- : Storage(a)
+ : Storage(a)
{
assign(str, pos, n);
}
-
+
flex_string(const value_type* s, const A& a = A())
: Storage(s, traits_type::length(s), a)
{}
-
+
flex_string(const value_type* s, size_type n, const A& a = A())
: Storage(s, n, a)
{}
-
+
flex_string(size_type n, value_type c, const A& a = A())
: Storage(n, c, a)
{}
@@ -264,14 +264,14 @@
~flex_string()
{}
-
+
flex_string& operator=(const flex_string& str)
{
Storage& s = *this;
s = str;
return *this;
- }
-
+ }
+
flex_string& operator=(const value_type* s)
{
assign(s);
@@ -283,67 +283,67 @@
assign(1, c);
return *this;
}
-
+
// 21.3.2 iterators:
iterator begin()
{ return Storage::begin(); }
-
+
const_iterator begin() const
{ return Storage::begin(); }
-
+
iterator end()
{ return Storage::end(); }
-
+
const_iterator end() const
{ return Storage::end(); }
reverse_iterator rbegin()
{ return reverse_iterator(end()); }
-
+
const_reverse_iterator rbegin() const
{ return const_reverse_iterator(end()); }
-
+
reverse_iterator rend()
{ return reverse_iterator(begin()); }
-
+
const_reverse_iterator rend() const
{ return const_reverse_iterator(begin()); }
-
+
// 21.3.3 capacity:
size_type size() const
{ return Storage::size(); }
-
+
size_type length() const
{ return size(); }
-
+
size_type max_size() const
{ return Storage::max_size(); }
void resize(size_type n, value_type c)
{ Storage::resize(n, c); }
-
+
void resize(size_type n)
{ resize(n, value_type()); }
-
+
size_type capacity() const
{ return Storage::capacity(); }
-
+
void reserve(size_type res_arg = 0)
{
Enforce(res_arg <= max_size(), static_cast<std::length_error*>(0), "");
Storage::reserve(res_arg);
}
-
+
void clear()
- { resize(0); }
-
+ { resize(0); }
+
bool empty() const
{ return size() == 0; }
-
+
// 21.3.4 element access:
const_reference operator[](size_type pos) const
{ return *(c_str() + pos); }
-
+
reference operator[](size_type pos)
{ return *(begin() + pos); }
@@ -352,42 +352,42 @@
Enforce(n <= size(), static_cast<std::out_of_range*>(0), "");
return (*this)[n];
}
-
+
reference at(size_type n)
{
Enforce(n < size(), static_cast<std::out_of_range*>(0), "");
return (*this)[n];
}
-
+
// 21.3.5 modifiers:
flex_string& operator+=(const flex_string& str)
{ return append(str); }
-
+
flex_string& operator+=(const value_type* s)
{ return append(s); }
flex_string& operator+=(const value_type c)
- {
+ {
push_back(c);
return *this;
}
-
+
flex_string& append(const flex_string& str)
{ return append(str.data(), str.length()); }
-
+
flex_string& append(const flex_string& str, const size_type pos,
size_type n)
- {
+ {
const size_type sz = str.size();
Enforce(pos <= sz, static_cast<std::out_of_range*>(0), "");
Procust(n, sz - pos);
- return append(str.data() + pos, n);
+ return append(str.data() + pos, n);
}
-
+
flex_string& append(const value_type* s, const size_type n)
- {
- Invariant checker(*this);
- (void) checker;
+ {
+ Invariant checker(*this);
+ (void) checker;
static std::less_equal<const value_type*> le;
if (le(&*begin(), s) && le(s, &*end())) // aliasing
{
@@ -395,28 +395,28 @@
Storage::reserve(size() + n);
s = &*begin() + offset;
}
- Storage::append(s, s + n);
+ Storage::append(s, s + n);
return *this;
}
-
+
flex_string& append(const value_type* s)
{ return append(s, traits_type::length(s)); }
-
+
flex_string& append(size_type n, value_type c)
- {
+ {
resize(size() + n, c);
return *this;
}
-
+
template<class InputIterator>
flex_string& append(InputIterator first, InputIterator last)
{
insert(end(), first, last);
return *this;
}
-
+
void push_back(const value_type c) // primitive
- {
+ {
const size_type cap = capacity();
if (size() == cap)
{
@@ -426,24 +426,24 @@
}
flex_string& assign(const flex_string& str)
- {
+ {
if (&str == this) return *this;
return assign(str.data(), str.size());
}
-
+
flex_string& assign(const flex_string& str, const size_type pos,
size_type n)
- {
+ {
const size_type sz = str.size();
Enforce(pos <= sz, static_cast<std::out_of_range*>(0), "");
Procust(n, sz - pos);
return assign(str.data() + pos, n);
}
-
+
flex_string& assign(const value_type* s, const size_type n)
{
- Invariant checker(*this);
- (void) checker;
+ Invariant checker(*this);
+ (void) checker;
if (size() >= n)
{
std::copy(s, s + n, begin());
@@ -457,57 +457,57 @@
}
return *this;
}
-
+
flex_string& assign(const value_type* s)
{ return assign(s, traits_type::length(s)); }
-
+
template <class ItOrLength, class ItOrChar>
flex_string& assign(ItOrLength first_or_n, ItOrChar last_or_c)
{ return replace(begin(), end(), first_or_n, last_or_c); }
-
+
flex_string& insert(size_type pos1, const flex_string& str)
{ return insert(pos1, str.data(), str.size()); }
-
+
flex_string& insert(size_type pos1, const flex_string& str,
size_type pos2, size_type n)
- {
+ {
Enforce(pos2 <= str.length(), static_cast<std::out_of_range*>(0), "");
Procust(n, str.length() - pos2);
- return insert(pos1, str.data() + pos2, n);
+ return insert(pos1, str.data() + pos2, n);
}
-
+
flex_string& insert(size_type pos, const value_type* s, size_type n)
- {
+ {
Enforce(pos <= length(), static_cast<std::out_of_range*>(0), "");
- insert(begin() + pos, s, s + n);
+ insert(begin() + pos, s, s + n);
return *this;
}
-
+
flex_string& insert(size_type pos, const value_type* s)
{ return insert(pos, s, traits_type::length(s)); }
-
+
flex_string& insert(size_type pos, size_type n, value_type c)
{
Enforce(pos <= length(), static_cast<std::out_of_range*>(0), "");
insert(begin() + pos, n, c);
return *this;
}
-
- iterator insert(const iterator p, const value_type c)
+
+ iterator insert(const iterator p, const value_type c)
{
const size_type pos = p - begin();
insert(p, 1, c);
return begin() + pos;
}
-
+
private:
template <int i> class Selector {};
- flex_string& InsertImplDiscr(iterator p,
+ flex_string& InsertImplDiscr(iterator p,
size_type n, value_type c, Selector<1>)
- {
- Invariant checker(*this);
- (void) checker;
+ {
+ Invariant checker(*this);
+ (void) checker;
assert(p >= begin() && p <= end());
if (capacity() - size() < n)
{
@@ -521,8 +521,8 @@
{
append(oldEnd - n, oldEnd);
//std::copy(
- // reverse_iterator(oldEnd - n),
- // reverse_iterator(p),
+ // reverse_iterator(oldEnd - n),
+ // reverse_iterator(p),
// reverse_iterator(oldEnd));
flex_string_details::pod_move(&*p, &*oldEnd - n, &*p + n);
std::fill(p, p + n, c);
@@ -534,13 +534,13 @@
std::fill(p, oldEnd, c);
}
return *this;
- }
+ }
template<class InputIterator>
flex_string& InsertImplDiscr(iterator i,
InputIterator b, InputIterator e, Selector<0>)
- {
- InsertImpl(i, b, e,
+ {
+ InsertImpl(i, b, e,
typename std::iterator_traits<InputIterator>::iterator_category());
return *this;
}
@@ -548,22 +548,24 @@
template <class FwdIterator>
void InsertImpl(iterator i,
FwdIterator s1, FwdIterator s2, std::forward_iterator_tag)
- {
- Invariant checker(*this);
+ {
+ // TODO: there is a bug in this method when the range to insert is inside the current range. See bug #2679853.
+
+ Invariant checker(*this);
(void) checker;
const size_type pos = i - begin();
- const typename std::iterator_traits<FwdIterator>::difference_type n2 =
+ const typename std::iterator_traits<FwdIterator>::difference_type n2 =
std::distance(s1, s2);
assert(n2 >= 0);
using namespace flex_string_details;
assert(pos <= size());
- const typename std::iterator_traits<FwdIterator>::difference_type maxn2 =
+ const typename std::iterator_traits<FwdIterator>::difference_type maxn2 =
capacity() - size();
if (maxn2 < n2)
{
// realloc the string
- static const std::less_equal<const value_type*> le =
+ static const std::less_equal<const value_type*> le =
std::less_equal<const value_type*>();
assert(!(le(&*begin(), &*s1) && le(&*s1, &*end())));
reserve(size() + n2);
@@ -577,7 +579,7 @@
const iterator tailBegin = end() - n2;
Storage::append(tailBegin, tailBegin + n2);
//std::copy(i, tailBegin, i + n2);
- std::copy(reverse_iterator(tailBegin), reverse_iterator(i),
+ std::copy(reverse_iterator(tailBegin), reverse_iterator(i),
reverse_iterator(tailBegin + n2));
std::copy(s1, s2, i);
}
@@ -596,7 +598,7 @@
template <class InputIterator>
void InsertImpl(iterator i1, iterator i2,
InputIterator b, InputIterator e, std::input_iterator_tag)
- {
+ {
flex_string temp(begin(), i1);
for (; b != e; ++b)
{
@@ -609,14 +611,14 @@
public:
template <class ItOrLength, class ItOrChar>
void insert(iterator p, ItOrLength first_or_n, ItOrChar last_or_c)
- {
+ {
Selector<std::numeric_limits<ItOrLength>::is_specialized> sel;
InsertImplDiscr(p, first_or_n, last_or_c, sel);
}
-
+
flex_string& erase(size_type pos = 0, size_type n = npos)
- {
- Invariant checker(*this);
+ {
+ Invariant checker(*this);
(void) checker;
Enforce(pos <= length(), static_cast<std::out_of_range*>(0), "");
Procust(n, length() - pos);
@@ -624,14 +626,14 @@
resize(length() - n);
return *this;
}
-
+
iterator erase(iterator position)
{
const size_type pos(position - begin());
erase(pos, 1);
return begin() + pos;
}
-
+
iterator erase(iterator first, iterator last)
{
const size_type pos(first - begin());
@@ -642,25 +644,25 @@
// Replaces at most n1 chars of *this, starting with pos1 with the content of str
flex_string& replace(size_type pos1, size_type n1, const flex_string& str)
{ return replace(pos1, n1, str.data(), str.size()); }
-
+
// Replaces at most n1 chars of *this, starting with pos1,
// with at most n2 chars of str starting with pos2
flex_string& replace(size_type pos1, size_type n1, const flex_string& str,
size_type pos2, size_type n2)
{
Enforce(pos2 <= str.length(), static_cast<std::out_of_range*>(0), "");
- return replace(pos1, n1, str.data() + pos2,
+ return replace(pos1, n1, str.data() + pos2,
Min(n2, str.size() - pos2));
}
-
+
/*
// Replaces at most n1 chars of *this, starting with pos,
// with at most n2 chars of str.
// str must have at least n2 chars.
- flex_string& replace(const size_type pos, size_type n1,
+ flex_string& replace(const size_type pos, size_type n1,
const value_type* s1, const size_type n2)
{
- Invariant checker(*this);
+ Invariant checker(*this);
(void) checker;
Enforce(pos <= size(), (std::out_of_range*)0, "");
Procust(n1, size() - pos);
@@ -735,43 +737,43 @@
// Replaces at most n1 chars of *this, starting with pos, with chars from s
flex_string& replace(size_type pos, size_type n1, const value_type* s)
{ return replace(pos, n1, s, traits_type::length(s)); }
-
+
// Replaces at most n1 chars of *this, starting with pos, with n2 occurences of c
// consolidated with
// Replaces at most n1 chars of *this, starting with pos,
// with at most n2 chars of str.
// str must have at least n2 chars.
template <class StrOrLength, class NumOrChar>
- flex_string& replace(size_type pos, size_type n1,
+ flex_string& replace(size_type pos, size_type n1,
StrOrLength s_or_n2, NumOrChar n_or_c)
{
- Invariant checker(*this);
+ Invariant checker(*this);
(void) checker;
Enforce(pos <= size(), static_cast<std::out_of_range*>(0), "");
Procust(n1, length() - pos);
const iterator b = begin() + pos;
return replace(b, b + n1, s_or_n2, n_or_c);
}
-
+
flex_string& replace(iterator i1, iterator i2, const flex_string& str)
{ return replace(i1, i2, str.data(), str.length()); }
-
+
flex_string& replace(iterator i1, iterator i2, const value_type* s)
{ return replace(i1, i2, s, traits_type::length(s)); }
-
+
private:
- flex_string& ReplaceImplDiscr(iterator i1, iterator i2,
+ flex_string& ReplaceImplDiscr(iterator i1, iterator i2,
const value_type* s, size_type n, Selector<2>)
- {
+ {
assert(i1 <= i2);
assert(begin() <= i1 && i1 <= end());
assert(begin() <= i2 && i2 <= end());
- return replace(i1, i2, s, s + n);
+ return replace(i1, i2, s, s + n);
}
-
+
flex_string& ReplaceImplDiscr(iterator i1, iterator i2,
size_type n2, value_type c, Selector<1>)
- {
+ {
const size_type n1 = i2 - i1;
if (n1 > n2)
{
@@ -784,13 +786,13 @@
insert(i2, n2 - n1, c);
}
return *this;
- }
+ }
template <class InputIterator>
flex_string& ReplaceImplDiscr(iterator i1, iterator i2,
InputIterator b, InputIterator e, Selector<0>)
- {
- ReplaceImpl(i1, i2, b, e,
+ {
+ ReplaceImpl(i1, i2, b, e,
typename std::iterator_traits<InputIterator>::iterator_category());
return *this;
}
@@ -798,14 +800,14 @@
template <class FwdIterator>
void ReplaceImpl(iterator i1, iterator i2,
FwdIterator s1, FwdIterator s2, std::forward_iterator_tag)
- {
- Invariant checker(*this);
+ {
+ Invariant checker(*this);
(void) checker;
- const typename std::iterator_traits<iterator>::difference_type n1 =
+ const typename std::iterator_traits<iterator>::difference_type n1 =
i2 - i1;
assert(n1 >= 0);
- const typename std::iterator_traits<FwdIterator>::difference_type n2 =
+ const typename std::iterator_traits<FwdIterator>::difference_type n2 =
std::distance(s1, s2);
assert(n2 >= 0);
@@ -813,7 +815,7 @@
if(0 != n2)
{
// Handle aliased replace
- static const std::less_equal<const value_type*> le =
+ static const std::less_equal<const value_type*> le =
std::less_equal<const value_type*>();
const bool aliased = le(&*begin(), &*s1) && le(&*s1, &*end());
if (aliased /* && capacity() < size() - n1 + n2 */)
@@ -855,45 +857,45 @@
template <class T1, class T2>
flex_string& replace(iterator i1, iterator i2,
T1 first_or_n_or_s, T2 last_or_c_or_n)
- {
- const bool
+ {
+ const bool
num1 = std::numeric_limits<T1>::is_specialized,
num2 = std::numeric_limits<T2>::is_specialized;
- return ReplaceImplDiscr(i1, i2, first_or_n_or_s, last_or_c_or_n,
- Selector<num1 ? (num2 ? 1 : -1) : (num2 ? 2 : 0)>());
+ return ReplaceImplDiscr(i1, i2, first_or_n_or_s, last_or_c_or_n,
+ Selector<num1 ? (num2 ? 1 : -1) : (num2 ? 2 : 0)>());
}
-
+
size_type copy(value_type* s, size_type n, size_type pos = 0) const
{
Enforce(pos <= size(), static_cast<std::out_of_range*>(0), "");
Procust(n, size() - pos);
-
+
flex_string_details::pod_copy(
data() + pos,
data() + pos + n,
s);
return n;
}
-
+
void swap(flex_string& rhs)
{
Storage& srhs = rhs;
this->Storage::swap(srhs);
}
-
+
// 21.3.6 string operations:
const value_type* c_str() const
{ return Storage::c_str(); }
-
+
const value_type* data() const
{ return Storage::data(); }
-
+
allocator_type get_allocator() const
{ return Storage::get_allocator(); }
-
+
size_type find(const flex_string& str, size_type pos = 0) const
{ return find(str.data(), pos, str.length()); }
-
+
size_type find (const value_type* s, size_type pos, size_type n) const
{
const size_type size(size());
@@ -908,16 +910,16 @@
}
return npos;
}
-
+
size_type find (const value_type* s, size_type pos = 0) const
{ return find(s, pos, traits_type::length(s)); }
size_type find (value_type c, size_type pos = 0) const
{ return find(&c, pos, 1); }
-
+
size_type rfind(const flex_string& str, size_type pos = npos) const
{ return rfind(str.data(), pos, str.length()); }
-
+
size_type rfind(const value_type* s, size_type pos, size_type n) const
{
if (n > length()) return npos;
@@ -927,7 +929,7 @@
const_iterator i(begin() + pos);
for (; ; --i)
{
- if (traits_type::eq(*i, *s)
+ if (traits_type::eq(*i, *s)
&& traits_type::compare(&*i, s, n) == 0)
{
return i - begin();
@@ -942,11 +944,11 @@
size_type rfind(value_type c, size_type pos = npos) const
{ return rfind(&c, pos, 1); }
-
+
size_type find_first_of(const flex_string& str, size_type pos = 0) const
{ return find_first_of(str.data(), pos, str.length()); }
-
- size_type find_first_of(const value_type* s,
+
+ size_type find_first_of(const value_type* s,
size_type pos, size_type n) const
{
if (pos > length() || n == 0) return npos;
@@ -961,18 +963,18 @@
}
return npos;
}
-
+
size_type find_first_of(const value_type* s, size_type pos = 0) const
{ return find_first_of(s, pos, traits_type::length(s)); }
-
+
size_type find_first_of(value_type c, size_type pos = 0) const
{ return find_first_of(&c, pos, 1); }
-
+
size_type find_last_of (const flex_string& str,
size_type pos = npos) const
{ return find_last_of(str.data(), pos, str.length()); }
-
- size_type find_last_of (const value_type* s, size_type pos,
+
+ size_type find_last_of (const value_type* s, size_type pos,
size_type n) const
{
if (!empty() && n > 0)
@@ -991,23 +993,23 @@
return npos;
}
- size_type find_last_of (const value_type* s,
+ size_type find_last_of (const value_type* s,
size_type pos = npos) const
{ return find_last_of(s, pos, traits_type::length(s)); }
size_type find_last_of (value_type c, size_type pos = npos) const
{ return find_last_of(&c, pos, 1); }
-
+
size_type find_first_not_of(const flex_string& str,
size_type pos = 0) const
{ return find_first_not_of(str.data(), pos, str.size()); }
-
+
size_type find_first_not_of(const value_type* s, size_type pos,
size_type n) const
{
if (pos < length())
{
- const_iterator
+ const_iterator
i(begin() + pos),
finish(end());
for (; i != finish; ++i)
@@ -1020,18 +1022,18 @@
}
return npos;
}
-
- size_type find_first_not_of(const value_type* s,
+
+ size_type find_first_not_of(const value_type* s,
size_type pos = 0) const
{ return find_first_not_of(s, pos, traits_type::length(s)); }
-
+
size_type find_first_not_of(value_type c, size_type pos = 0) const
{ return find_first_not_of(&c, pos, 1); }
-
+
size_type find_last_not_of(const flex_string& str,
size_type pos = npos) const
{ return find_last_not_of(str.data(), pos, str.length()); }
-
+
size_type find_last_not_of(const value_type* s, size_type pos,
size_type n) const
{
@@ -1051,13 +1053,13 @@
return npos;
}
- size_type find_last_not_of(const value_type* s,
+ size_type find_last_not_of(const value_type* s,
size_type pos = npos) const
{ return find_last_not_of(s, pos, traits_type::length(s)); }
-
+
size_type find_last_not_of (value_type c, size_type pos = npos) const
{ return find_last_not_of(&c, pos, 1); }
-
+
flex_string substr(size_type pos = 0, size_type n = npos) const
{
Enforce(pos <= size(), static_cast<std::out_of_range*>(0), "");
@@ -1065,16 +1067,16 @@
}
int compare(const flex_string& str) const
- {
+ {
// FIX due to Goncalo N M de Carvalho July 18, 2005
return compare(0, size(), str);
}
-
+
int compare(size_type pos1, size_type n1,
const flex_string& str) const
{ return compare(pos1, n1, str.data(), str.size()); }
-
- // FIX to compare: added the TC
+
+ // FIX to compare: added the TC
// (http://www.comeaucomputing.com/iso/lwg-defects.html number 5)
// Thanks to Caleb Epstein for the fix
@@ -1083,7 +1085,7 @@
{
return compare(pos1, n1, s, traits_type::length(s));
}
-
+
int compare(size_type pos1, size_type n1,
const value_type* s, size_type n2) const
{
@@ -1093,7 +1095,7 @@
const int r = traits_type::compare(pos1 + data(), s, Min(n1, n2));
return r != 0 ? r : n1 > n2 ? 1 : n1 < n2 ? -1 : 0;
}
-
+
int compare(size_type pos1, size_type n1,
const flex_string& str,
size_type pos2, size_type n2) const
@@ -1115,7 +1117,7 @@
// non-member functions
template <typename E, class T, class A, class S>
-flex_string<E, T, A, S> operator+(const flex_string<E, T, A, S>& lhs,
+flex_string<E, T, A, S> operator+(const flex_string<E, T, A, S>& lhs,
const flex_string<E, T, A, S>& rhs)
{
flex_string<E, T, A, S> result;
@@ -1125,11 +1127,11 @@
}
template <typename E, class T, class A, class S>
-flex_string<E, T, A, S> operator+(const typename flex_string<E, T, A, S>::value_type* lhs,
+flex_string<E, T, A, S> operator+(const typename flex_string<E, T, A, S>::value_type* lhs,
const flex_string<E, T, A, S>& rhs)
{
flex_string<E, T, A, S> result;
- const typename flex_string<E, T, A, S>::size_type len =
+ const typename flex_string<E, T, A, S>::size_type len =
flex_string<E, T, A, S>::traits_type::length(lhs);
result.reserve(len + rhs.size());
result.append(lhs, len).append(rhs);
@@ -1138,7 +1140,7 @@
template <typename E, class T, class A, class S>
flex_string<E, T, A, S> operator+(
- typename flex_string<E, T, A, S>::value_type lhs,
+ typename flex_string<E, T, A, S>::value_type lhs,
const flex_string<E, T, A, S>& rhs)
{
flex_string<E, T, A, S> result;
@@ -1149,7 +1151,7 @@
}
template <typename E, class T, class A, class S>
-flex_string<E, T, A, S> operator+(const flex_string<E, T, A, S>& lhs,
+flex_string<E, T, A, S> operator+(const flex_string<E, T, A, S>& lhs,
const typename flex_string<E, T, A, S>::value_type* rhs)
{
typedef typename flex_string<E, T, A, S>::size_type size_type;
@@ -1163,7 +1165,7 @@
}
template <typename E, class T, class A, class S>
-flex_string<E, T, A, S> operator+(const flex_string<E, T, A, S>& lhs,
+flex_string<E, T, A, S> operator+(const flex_string<E, T, A, S>& lhs,
typename flex_string<E, T, A, S>::value_type rhs)
{
flex_string<E, T, A, S> result;
@@ -1174,92 +1176,92 @@
}
template <typename E, class T, class A, class S>
-bool operator==(const flex_string<E, T, A, S>& lhs,
+bool operator==(const flex_string<E, T, A, S>& lhs,
const flex_string<E, T, A, S>& rhs)
{ return lhs.compare(rhs) == 0; }
template <typename E, class T, class A, class S>
-bool operator==(const typename flex_string<E, T, A, S>::value_type* lhs,
+bool operator==(const typename flex_string<E, T, A, S>::value_type* lhs,
const flex_string<E, T, A, S>& rhs)
{ return rhs == lhs; }
template <typename E, class T, class A, class S>
-bool operator==(const flex_string<E, T, A, S>& lhs,
+bool operator==(const flex_string<E, T, A, S>& lhs,
const typename flex_string<E, T, A, S>::value_type* rhs)
{ return lhs.compare(rhs) == 0; }
template <typename E, class T, class A, class S>
-bool operator!=(const flex_string<E, T, A, S>& lhs,
+bool operator!=(const flex_string<E, T, A, S>& lhs,
const flex_string<E, T, A, S>& rhs)
{ return !(lhs == rhs); }
template <typename E, class T, class A, class S>
-bool operator!=(const typename flex_string<E, T, A, S>::value_type* lhs,
+bool operator!=(const typename flex_string<E, T, A, S>::value_type* lhs,
const flex_string<E, T, A, S>& rhs)
{ return !(lhs == rhs); }
template <typename E, class T, class A, class S>
-bool operator!=(const flex_string<E, T, A, S>& lhs,
+bool operator!=(const flex_string<E, T, A, S>& lhs,
const typename flex_string<E, T, A, S>::value_type* rhs)
{ return !(lhs == rhs); }
template <typename E, class T, class A, class S>
-bool operator<(const flex_string<E, T, A, S>& lhs,
+bool operator<(const flex_string<E, T, A, S>& lhs,
const flex_string<E, T, A, S>& rhs)
{ return lhs.compare(rhs) < 0; }
template <typename E, class T, class A, class S>
-bool operator<(const flex_string<E, T, A, S>& lhs,
+bool operator<(const flex_string<E, T, A, S>& lhs,
const typename flex_string<E, T, A, S>::value_type* rhs)
{ return lhs.compare(rhs) < 0; }
template <typename E, class T, class A, class S>
-bool operator<(const typename flex_string<E, T, A, S>::value_type* lhs,
+bool operator<(const typename flex_string<E, T, A, S>::value_type* lhs,
const flex_string<E, T, A, S>& rhs)
{ return rhs.compare(lhs) > 0; }
template <typename E, class T, class A, class S>
-bool operator>(const flex_string<E, T, A, S>& lhs,
+bool operator>(const flex_string<E, T, A, S>& lhs,
const flex_string<E, T, A, S>& rhs)
{ return rhs < lhs; }
template <typename E, class T, class A, class S>
-bool operator>(const flex_string<E, T, A, S>& lhs,
+bool operator>(const flex_string<E, T, A, S>& lhs,
const typename flex_string<E, T, A, S>::value_type* rhs)
{ return rhs < lhs; }
template <typename E, class T, class A, class S>
-bool operator>(const typename flex_string<E, T, A, S>::value_type* lhs,
+bool operator>(const typename flex_string<E, T, A, S>::value_type* lhs,
const flex_string<E, T, A, S>& rhs)
{ return rhs < lhs; }
template <typename E, class T, class A, class S>
-bool operator<=(const flex_string<E, T, A, S>& lhs,
+bool operator<=(const flex_string<E, T, A, S>& lhs,
const flex_string<E, T, A, S>& rhs)
{ return !(rhs < lhs); }
template <typename E, class T, class A, class S>
-bool operator<=(const flex_string<E, T, A, S>& lhs,
+bool operator<=(const flex_string<E, T, A, S>& lhs,
const typename flex_string<E, T, A, S>::value_type* rhs)
{ return !(rhs < lhs); }
template <typename E, class T, class A, class S>
-bool operator<=(const typename flex_string<E, T, A, S>::value_type* lhs,
+bool operator<=(const typename flex_string<E, T, A, S>::value_type* lhs,
const flex_string<E, T, A, S>& rhs)
{ return !(rhs < lhs); }
template <typename E, class T, class A, class S>
-bool operator>=(const flex_string<E, T, A, S>& lhs,
+bool operator>=(const flex_string<E, T, A, S>& lhs,
const flex_string<E, T, A, S>& rhs)
{ return !(lhs < rhs); }
template <typename E, class T, class A, class S>
-bool operator>=(const flex_string<E, T, A, S>& lhs,
+bool operator>=(const flex_string<E, T, A, S>& lhs,
const typename flex_string<E, T, A, S>::value_type* rhs)
{ return !(lhs < rhs); }
template <typename E, class T, class A, class S>
-bool operator>=(const typename flex_string<E, T, A, S>::value_type* lhs,
+bool operator>=(const typename flex_string<E, T, A, S>::value_type* lhs,
const flex_string<E, T, A, S>& rhs)
{ return !(lhs < rhs); }
@@ -1267,10 +1269,10 @@
//void swap(flex_string<E, T, A, S>& lhs, flex_string<E, T, A, S>& rhs); // to do
template <typename E, class T, class A, class S>
-std::basic_istream<typename flex_string<E, T, A, S>::value_type,
+std::basic_istream<typename flex_string<E, T, A, S>::value_type,
typename flex_string<E, T, A, S>::traits_type>&
operator>>(
- std::basic_istream<typename flex_string<E, T, A, S>::value_type,
+ std::basic_istream<typename flex_string<E, T, A, S>::value_type,
typename flex_string<E, T, A, S>::traits_type>& is,
flex_string<E, T, A, S>& str);
@@ -1278,7 +1280,7 @@
std::basic_ostream<typename flex_string<E, T, A, S>::value_type,
typename flex_string<E, T, A, S>::traits_type>&
operator<<(
- std::basic_ostream<typename flex_string<E, T, A, S>::value_type,
+ std::basic_ostream<typename flex_string<E, T, A, S>::value_type,
typename flex_string<E, T, A, S>::traits_type>& os,
const flex_string<E, T, A, S>& str)
{ return os << str.c_str(); }
@@ -1287,7 +1289,7 @@
std::basic_istream<typename flex_string<E, T, A, S>::value_type,
typename flex_string<E, T, A, S>::traits_type>&
getline(
- std::basic_istream<typename flex_string<E, T, A, S>::value_type,
+ std::basic_istream<typename flex_string<E, T, A, S>::value_type,
typename flex_string<E, T, A, S>::traits_type>& is,
flex_string<E, T, A, S>& str,
typename flex_string<E, T, A, S>::value_type delim)
@@ -1309,7 +1311,7 @@
else {
++nread;
typename flex_string<E, T, A, S>::value_type c = flex_string<E, T, A, S>::traits_type::to_char_type(c1);
- if (!flex_string<E, T, A, S>::traits_type::eq(c, delim))
+ if (!flex_string<E, T, A, S>::traits_type::eq(c, delim))
str.push_back(c);
else
break; // Character is extracted but not appended.
@@ -1323,10 +1325,10 @@
}
template <typename E, class T, class A, class S>
-std::basic_istream<typename flex_string<E, T, A, S>::value_type,
+std::basic_istream<typename flex_string<E, T, A, S>::value_type,
typename flex_string<E, T, A, S>::traits_type>&
getline(
- std::basic_istream<typename flex_string<E, T, A, S>::value_type,
+ std::basic_istream<typename flex_string<E, T, A, S>::value_type,
typename flex_string<E, T, A, S>::traits_type>& is,
flex_string<E, T, A, S>& str)
{
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jfb...@us...> - 2009-03-10 19:56:19
|
Revision: 1003
http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1003&view=rev
Author: jfbastien
Date: 2009-03-10 19:55:59 +0000 (Tue, 10 Mar 2009)
Log Message:
-----------
Simplify Num2String.
Modified Paths:
--------------
trunk/test/flex_string/main.cpp
Modified: trunk/test/flex_string/main.cpp
===================================================================
--- trunk/test/flex_string/main.cpp 2009-03-10 18:36:42 UTC (rev 1002)
+++ trunk/test/flex_string/main.cpp 2009-03-10 19:55:59 UTC (rev 1003)
@@ -208,10 +208,7 @@
{
if(String::npos != value)
{
- typedef typename String::value_type CharType;
- std::basic_ostringstream<CharType, std::char_traits<CharType>, std::allocator<CharType> > stream;
- stream << OpenCurlyString<String>() << value << CloseCurlyString<String>();
- return stream.str().c_str();
+ return Num2String<String, typename String::size_type>(value);
}
else
{
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jfb...@us...> - 2009-03-10 18:36:55
|
Revision: 1002
http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1002&view=rev
Author: jfbastien
Date: 2009-03-10 18:36:42 +0000 (Tue, 10 Mar 2009)
Log Message:
-----------
Refactor some more, and add a bunch of tests. These new tests led me to find bug #2679853.
Modified Paths:
--------------
trunk/test/flex_string/main.cpp
Modified: trunk/test/flex_string/main.cpp
===================================================================
--- trunk/test/flex_string/main.cpp 2009-03-05 22:04:56 UTC (rev 1001)
+++ trunk/test/flex_string/main.cpp 2009-03-10 18:36:42 UTC (rev 1002)
@@ -133,19 +133,73 @@
return result;
}
-// Specialize this method for different String types.
+// Specialize these method for different String types.
template<class String>
-String Npos()
+typename String::value_type NullTerminator()
{
+ return '\0';
+}
+
+template<class String>
+String LengthErrorExceptionString()
+{
+ return "length_error exception thrown";
+}
+
+template<class String>
+String OutOfRangeExceptionString()
+{
+ return "out_of_range exception thrown";
+}
+
+template<class String>
+String UnknownExceptionString()
+{
+ return "Unknown exception thrown";
+}
+
+template<class String>
+String NposString()
+{
return "{npos}";
}
+template<class String>
+String OpenCurlyString()
+{
+ return "{";
+}
+
+template<class String>
+String CloseCurlyString()
+{
+ return "}";
+}
+
+template<class String>
+String SeparatorString()
+{
+ return "--";
+}
+
+template<class String>
+String TrueString()
+{
+ return "{true}";
+}
+
+template<class String>
+String FalseString()
+{
+ return "{false}";
+}
+
template<class String, class Integral>
String Num2String(Integral value)
{
typedef typename String::value_type CharType;
std::basic_ostringstream<CharType, std::char_traits<CharType>, std::allocator<CharType> > stream;
- stream << value;
+ stream << OpenCurlyString<String>() << value << CloseCurlyString<String>();
return stream.str().c_str();
}
@@ -156,17 +210,23 @@
{
typedef typename String::value_type CharType;
std::basic_ostringstream<CharType, std::char_traits<CharType>, std::allocator<CharType> > stream;
- stream << value;
+ stream << OpenCurlyString<String>() << value << CloseCurlyString<String>();
return stream.str().c_str();
}
else
{
// Not all strings will have the same value for npos.
// Since methods like find return npos on failure we want to represent npos in an implementation-independent manner.
- return Npos<String>();
+ return NposString<String>();
}
}
+template<class String>
+String Num2String(bool value)
+{
+ return value ? TrueString<String>() : FalseString<String>();
+}
+
// Some comparison functions return 0 or a value greater/smaller than zero.
// This function makes the greater/smaller than zero specification implementation-independent.
template<class String>
@@ -184,13 +244,13 @@
std::list<typename String::value_type> RandomList(typename String::size_type maxSize)
{
const typename String::size_type size = random(0, maxSize);
- std::list<typename String::value_type> lst(size);
- std::list<typename String::value_type>::iterator i = lst.begin();
- for (; i != lst.end(); ++i)
+ std::list<typename String::value_type> list(size);
+ std::list<typename String::value_type>::iterator i = list.begin();
+ for (; i != list.end(); ++i)
{
*i = random('a', 'z');
}
- return lst;
+ return list;
}
namespace Tests
@@ -201,1274 +261,2424 @@
static const typename String::size_type value = 1050;
};
+ template<class String>
+ String operator_plus_string_string()
+ {
+ // 21.3
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ String result;
+ result = random1 + random2;
+ return result;
+ }
template<class String>
- String default_constructor(String &)
+ String operator_plus_cstr_string()
{
+ // 21.3
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ String result;
+ result = random1.c_str() + random2;
+ return result;
+ }
+
+ template<class String>
+ String operator_plus_char_string()
+ {
+ // 21.3
+ const typename String::value_type value = random('a', 'z');
+ String random1(RandomString<String>(MaxString<String>::value));
+ String result;
+ result = value + random1;
+ return result;
+ }
+
+ template<class String>
+ String operator_plus_string_cstr()
+ {
+ // 21.3
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ String result;
+ result = random1 + random2.c_str();
+ return result;
+ }
+
+ template<class String>
+ String operator_plus_string_char()
+ {
+ // 21.3
+ const typename String::value_type value = random('a', 'z');
+ String random1(RandomString<String>(MaxString<String>::value));
+ String result;
+ result = random1 + value;
+ return result;
+ }
+
+ template<class String>
+ String operator_equal_equal_string_string()
+ {
+ // 21.3
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ String result;
+ result = Num2String<String>(random1 == random2);
+ return result;
+ }
+
+ template<class String>
+ String operator_equal_equal_cstr_string()
+ {
+ // 21.3
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ String result;
+ result = Num2String<String>(random1.c_str() == random2);
+ return result;
+ }
+
+ template<class String>
+ String operator_equal_equal_string_cstr()
+ {
+ // 21.3
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ String result;
+ result = Num2String<String>(random1 == random2.c_str());
+ return result;
+ }
+
+ template<class String>
+ String operator_not_equal_string_string()
+ {
+ // 21.3
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ String result;
+ result = Num2String<String>(random1 != random2);
+ return result;
+ }
+
+ template<class String>
+ String operator_not_equal_cstr_string()
+ {
+ // 21.3
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ String result;
+ result = Num2String<String>(random1.c_str() != random2);
+ return result;
+ }
+
+ template<class String>
+ String operator_not_equal_string_cstr()
+ {
+ // 21.3
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ String result;
+ result = Num2String<String>(random1 != random2.c_str());
+ return result;
+ }
+
+ template<class String>
+ String operator_smaller_string_string()
+ {
+ // 21.3
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ String result;
+ result = Num2String<String>(random1 < random2);
+ return result;
+ }
+
+ template<class String>
+ String operator_smaller_cstr_string()
+ {
+ // 21.3
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ String result;
+ result = Num2String<String>(random1.c_str() < random2);
+ return result;
+ }
+
+ template<class String>
+ String operator_smaller_string_cstr()
+ {
+ // 21.3
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ String result;
+ result = Num2String<String>(random1 < random2.c_str());
+ return result;
+ }
+
+ template<class String>
+ String operator_greater_string_string()
+ {
+ // 21.3
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ String result;
+ result = Num2String<String>(random1 > random2);
+ return result;
+ }
+
+ template<class String>
+ String operator_greater_cstr_string()
+ {
+ // 21.3
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ String result;
+ result = Num2String<String>(random1.c_str() > random2);
+ return result;
+ }
+
+ template<class String>
+ String operator_greater_string_cstr()
+ {
+ // 21.3
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ String result;
+ result = Num2String<String>(random1 > random2.c_str());
+ return result;
+ }
+
+ template<class String>
+ String operator_smaller_equal_string_string()
+ {
+ // 21.3
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ String result;
+ result = Num2String<String>(random1 <= random2);
+ return result;
+ }
+
+ template<class String>
+ String operator_smaller_equal_cstr_string()
+ {
+ // 21.3
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ String result;
+ result = Num2String<String>(random1.c_str() <= random2);
+ return result;
+ }
+
+ template<class String>
+ String operator_smaller_equal_string_cstr()
+ {
+ // 21.3
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ String result;
+ result = Num2String<String>(random1 <= random2.c_str());
+ return result;
+ }
+
+ template<class String>
+ String operator_greater_equal_string_string()
+ {
+ // 21.3
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ String result;
+ result = Num2String<String>(random1 >= random2);
+ return result;
+ }
+
+ template<class String>
+ String operator_greater_equal_cstr_string()
+ {
+ // 21.3
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ String result;
+ result = Num2String<String>(random1.c_str() >= random2);
+ return result;
+ }
+
+ template<class String>
+ String operator_greater_equal_string_cstr()
+ {
+ // 21.3
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ String result;
+ result = Num2String<String>(random1 >= random2.c_str());
+ return result;
+ }
+
+ template<class String>
+ String swap_string_string()
+ {
+ using std::swap;
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ swap(random1, random2);
+ return random1 + SeparatorString<String>() + random2;
+ }
+
+ template<class String>
+ String swap_string_string__self()
+ {
+ using std::swap;
+ String random1(RandomString<String>(MaxString<String>::value));
+ swap(random1, random1);
+ return random1;
+ }
+
+ template<class String>
+ String swap_string_string__selfcopy()
+ {
+ using std::swap;
+ String random1(RandomString<String>(MaxString<String>::value));
+ String copy(random1);
+ swap(random1, copy);
+ return random1 + SeparatorString<String>() + copy;
+ }
+
+ template<class String>
+ String swap_string_string__selfcopy2()
+ {
+ using std::swap;
+ String random1(RandomString<String>(MaxString<String>::value));
+ String copy(random1);
+ swap(copy, random1);
+ return random1 + SeparatorString<String>() + copy;
+ }
+
+ // TODO: operator>>(istream, string)
+ // TODO: operator<<(ostream, string)
+ // TODO: getline(istream, string, char delimiter)
+ // TODO: getline(istream, string)
+
+ template<class String>
+ String constructor()
+ {
// 21.3.1
return String();
}
template<class String>
- String copy_constructor(String & test)
+ String constructor_string()
{
// 21.3.1
- String s(test);
- return s;
+ String random1(RandomString<String>(MaxString<String>::value));
+ return random1;
}
template<class String>
- String copy_constructor_with_size_and_range(String & test)
+ String constructor_string_position_number()
{
// 21.3.1
- const typename String::size_type pos = random(0, test.size());
- const typename String::size_type length = random(0, test.size() - pos);
- String s(test, pos, length);
- return s;
+ String random1(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type position = random(0, random1.size());
+ const typename String::size_type number = random(0, random1.size() - position);
+ String result(random1, position, number);
+ return result;
}
template<class String>
- String constructor_with_cstr_and_size(String & test)
+ String constructor_string_position_number__bigNumber()
{
// 21.3.1
- const typename String::size_type pos = random(0, test.size());
- const typename String::size_type n = random(0, test.size() - pos);
- String s(test.c_str() + pos, n);
- return s;
+ String random1(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type position = random(0, random1.size());
+ const typename String::size_type number = random(0, String::npos);
+ String result(random1, position, number);
+ return result;
}
template<class String>
- String constructor_with_cstr(String & test)
+ String constructor_cstr_number()
{
// 21.3.1
- const typename String::size_type pos = random(0, test.size());
- String s(test.c_str() + pos);
- return s;
+ String random1(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type number = random(0, random1.size());
+ String result(random1.c_str(), number);
+ return result;
}
template<class String>
- String assignment(String & test)
+ String constructor_number_char()
{
// 21.3.1
- const typename String::size_type size = random(0, MaxString<String>::value);
- String s(size, '\0');
- typename String::size_type i = 0;
- for (; i != s.size(); ++i)
- {
- s[i] = random('a', 'z');
- }
- test = s;
- return test;
+ const typename String::size_type number = random(0, MaxString<String>::value);
+ const typename String::size_type value = random('a', 'z');
+ String result(number, value);
+ return result;
}
template<class String>
- String assignment_with_cstr(String & test)
+ String constructor_iterator_iterator()
{
+ // 21.3.5
+ std::list<typename String::value_type> list(RandomList<String>(MaxString<String>::value));
+ String result(list.begin(), list.end());
+ return result;
+ }
+
+ // TODO: destructor
+
+ template<class String>
+ String operator_equal_string()
+ {
// 21.3.1
- const typename String::size_type size = random(0, MaxString<String>::value);
- String s(size, '\0');
- typename String::size_type i = 0;
- for (; i != s.size(); ++i)
- {
- s[i] = random('a', 'z');
- }
- test = s.c_str();
- return test;
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ random1 = random2;
+ return random1 + SeparatorString<String>() + random2;
}
template<class String>
- String assignment_aliased(String & test)
+ String operator_equal_string__self()
{
// 21.3.1
- const size_t pos = random(0, test.size());
- test = test.c_str() + pos;
- return test;
+ String random1(RandomString<String>(MaxString<String>::value));
+ random1 = random1;
+ return random1;
}
template<class String>
- String assignment_non_aliased(String & test)
+ String operator_equal_string__selfCopy()
{
// 21.3.1
- const size_t pos = random(0, test.size());
- test = String(test.c_str() + pos);
- return test;
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(random1);
+ random1 = random2;
+ return random1 + SeparatorString<String>() + random2;
}
template<class String>
- String assignment_from_char(String & test)
+ String operator_equal_cstr()
{
// 21.3.1
- test = random('a', 'z');
- return test;
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ random1 = random2.c_str();
+ return random1 + SeparatorString<String>() + random2;
}
template<class String>
- String iterators_call(String & test)
+ String operator_equal_cstr__self()
{
+ // 21.3.1
+ String random1(RandomString<String>(MaxString<String>::value));
+ random1 = random1.c_str();
+ return random1;
+ }
+
+ template<class String>
+ String operator_equal_cstr__selfCopy()
+ {
+ // 21.3.1
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(random1);
+ random1 = random2.c_str();
+ return random1 + SeparatorString<String>() + random2;
+ }
+
+ template<class String>
+ String iterators()
+ {
// 21.3.2
+ String random1(RandomString<String>(MaxString<String>::value));
+ const String random2(RandomString<String>(MaxString<String>::value));
String result;
- result += Num2String<String>(test.end() - test.begin()) + " -- ";
- result += Num2String<String>(test.rend() - test.rbegin()) + " -- ";
+ result += Num2String<String>(random1.end() - random1.begin())
+ + Num2String<String>(random1.rend() - random1.rbegin())
+ + Num2String<String>(random2.end() - random2.begin())
+ + Num2String<String>(random2.rend() - random2.rbegin())
+ + Num2String<String>(random1.end() == random1.begin())
+ + Num2String<String>(random1.rend() == random1.rbegin())
+ + Num2String<String>(random2.end() == random2.begin())
+ + Num2String<String>(random2.rend() == random2.rbegin())
+ + Num2String<String>(random1.end() != random1.begin())
+ + Num2String<String>(random1.rend() != random1.rbegin())
+ + Num2String<String>(random2.end() != random2.begin())
+ + Num2String<String>(random2.rend() != random2.rbegin());
return result;
}
template<class String>
- String iterators_equality(String & test)
+ String capacity()
{
- // 21.3.2
+ // 21.3.3
+ String random1(RandomString<String>(MaxString<String>::value));
String result;
- result += Num2String<String>(test.size()) + " -- ";
- if(0 != test.size())
+ result += Num2String<String>(random1.size())
+ + Num2String<String>(random1.length())
+ + Num2String<String>(random1.size() == random1.length())
+ + Num2String<String>(random1.capacity() >= random1.size())
+ + Num2String<String>(random1.max_size() >= random1.size())
+ + Num2String<String>(random1.max_size() >= random1.capacity());
+ return result;
+ }
+
+ template<class String>
+ String resize_number_char()
+ {
+ // 21.3.3
+ String random1(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type number = random(0, MaxString<String>::value);
+ const typename String::value_type value = random('a', 'z');
+ random1.resize(number, value);
+ return random1;
+ }
+
+ template<class String>
+ String resize_number()
+ {
+ // 21.3.3
+ String random1(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type number = random(0, MaxString<String>::value);
+ random1.resize(number);
+ return random1;
+ }
+
+ template<class String>
+ String reserve_number()
+ {
+ // 21.3.3
+ String random1(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type number = random(0, MaxString<String>::value);
+ random1.reserve(number);
+ random1 += Num2String<String>(random1.capacity() >= number);
+ return random1;
+ }
+
+ template<class String>
+ String clear()
+ {
+ // 21.3.3
+ String random1(RandomString<String>(MaxString<String>::value));
+ random1.clear();
+ return random1;
+ }
+
+ template<class String>
+ String empty()
+ {
+ // 21.3.3
+ String random1(RandomString<String>(MaxString<String>::value));
+ return Num2String<String>(random1.empty());
+ }
+
+ template<class String>
+ String element_access()
+ {
+ // 21.3.4
+ String random1(RandomString<String>(MaxString<String>::value));
+ const String random2(RandomString<String>(MaxString<String>::value));
+ String result;
+ if(!random1.empty())
{
- result += Num2String<String>(test.begin() != test.end()) + " -- ";
- result += Num2String<String>(test.rbegin() != test.rend()) + " -- ";
+ {
+ const typename String::size_type index = random(0, random1.size() - 1);
+ result += random1[index] + SeparatorString<String>();
+ }
+ {
+ const typename String::size_type index = random(0, random1.size() - 1);
+ result += random1.at(index) + SeparatorString<String>();
+ }
}
- else
+ if(!random2.empty())
{
- result += Num2String<String>(test.begin() == test.end()) + " -- ";
- result += Num2String<String>(test.rbegin() == test.rend()) + " -- ";
+ {
+ const typename String::size_type index = random(0, random2.size() - 1);
+ result += random2[index] + SeparatorString<String>();
+ }
+ {
+ const typename String::size_type index = random(0, random2.size() - 1);
+ result += random2.at(index) + SeparatorString<String>();
+ }
}
return result;
}
template<class String>
- String capacity(String & test)
+ String operator_plus_equal_string()
{
- // 21.3.2
- String result;
- result += Num2String<String>(test.size()) + " -- ";
- result += Num2String<String>(test.length()) + " -- ";
- test.max_size();
- test.capacity();
- result += test;
- return result;
+ // 21.3.5
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ random1 += random2;
+ return random1 + SeparatorString<String>() + random2;
}
template<class String>
- String capacity_values(String & test)
+ String operator_plus_equal_string__self()
{
- // 21.3.2
- String result;
- result += Num2String<String>(test.size() == test.length()) + " -- ";
- result += Num2String<String>(test.capacity() >= test.size()) + " -- ";
- result += Num2String<String>(test.max_size() >= test.size()) + " -- ";
- result += Num2String<String>(test.max_size() >= test.capacity()) + " -- ";
- return result;
+ // 21.3.5
+ String random1(RandomString<String>(MaxString<String>::value));
+ random1 += random1;
+ return random1;
}
template<class String>
- String resize(String & test)
+ String operator_plus_equal_string__selfcopy()
{
- const typename String::size_type newSize = random(0, test.size());
- const typename String::value_type value = random('a', 'z');
- test.resize(newSize, value);
- return test;
+ // 21.3.5
+ String random1(RandomString<String>(MaxString<String>::value));
+ String copy(random1);
+ random1 += copy;
+ return random1 + SeparatorString<String>() + copy;
}
template<class String>
- String resize_with_1_argument(String & test)
+ String operator_plus_equal_cstr()
{
- const typename String::size_type newSize = random(0, test.size());
- test.resize(newSize);
- return test;
+ // 21.3.5
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ random1 += random2.c_str();
+ return random1 + SeparatorString<String>() + random2;
}
template<class String>
- String reserve(String & test)
+ String operator_plus_equal_cstr__self()
{
- const typename String::size_type reserveSize = random(0, MaxString<String>::value);
- test.reserve(reserveSize);
- return test;
+ // 21.3.5
+ String random1(RandomString<String>(MaxString<String>::value));
+ random1 += random1.c_str();
+ return random1;
}
template<class String>
- String clear(String & test)
+ String operator_plus_equal_cstr__selfcopy()
{
- test.clear();
- return test;
+ // 21.3.5
+ String random1(RandomString<String>(MaxString<String>::value));
+ String copy(random1);
+ random1 += copy.c_str();
+ return random1 + SeparatorString<String>() + copy;
}
template<class String>
- String empty1(String & test)
+ String operator_plus_equal_char()
{
- if (test.empty()) test = "empty";
- else test = "not empty";
- return test;
+ // 21.3.5
+ String random1(RandomString<String>(MaxString<String>::value));
+ const typename String::value_type value = random('a', 'z');
+ random1 += value;
+ return random1;
}
template<class String>
- String empty2(String & test)
+ String append_string()
{
- const char* kEmptyString = "empty";
- const char* kNonEmptyString = "not empty";
- if (test.empty()) test = String(kEmptyString, kEmptyString + strlen(kEmptyString));
- else test = String(kNonEmptyString, kNonEmptyString + strlen(kNonEmptyString));
- return test;
+ // 21.3.5
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ random1.append(random2);
+ return random1 + SeparatorString<String>() + random2;
}
template<class String>
- String element_access(String & test)
+ String append_string__self()
{
- // 21.3.4
- if(!test.empty())
- {
- const typename String::size_type index1 = random(0, test.size() - 1);
- test += test[index1];
- const typename String::size_type index2 = random(0, test.size() - 1);
- test += test.at(index2);
- }
- return test;
+ // 21.3.5
+ String random1(RandomString<String>(MaxString<String>::value));
+ random1.append(random1);
+ return random1;
}
template<class String>
- String operator_plus_equal(String & test)
+ String append_string__selfcopy()
{
- String str(RandomString<String>(MaxString<String>::value));
- test += str;
- return test;
+ // 21.3.5
+ String random1(RandomString<String>(MaxString<String>::value));
+ String copy(random1);
+ random1.append(copy);
+ return random1 + SeparatorString<String>() + copy;
}
template<class String>
- String operator_plus_equal_aliasing(String & test)
+ String append_string_position_number()
{
- test += test;
- return test;
+ // 21.3.5
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type position = random(0, random2.size());
+ const typename String::size_type number = random(0, MaxString<String>::value);
+ random1.append(random2, position, number);
+ return random1 + SeparatorString<String>() + random2;
}
template<class String>
- String operator_plus_equal_with_cstr(String & test)
+ String append_string_position_number__self()
{
// 21.3.5
- String str(RandomString<String>(MaxString<String>::value));
- test += str.c_str();
- return test;
+ String random1(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type position = random(0, random1.size());
+ const typename String::size_type number = random(0, MaxString<String>::value);
+ random1.append(random1, position, number);
+ return random1;
}
template<class String>
- String operator_plus_equal_no_aliasing(String & test)
+ String append_string_position_number__selfcopy()
{
// 21.3.5
- const typename String::size_type offset = random(0, test.size());
- test += String(test.c_str() + offset);
- return test;
+ String random1(RandomString<String>(MaxString<String>::value));
+ String copy(random1);
+ const typename String::size_type position = random(0, random1.size());
+ const typename String::size_type number = random(0, MaxString<String>::value);
+ random1.append(copy, position, number);
+ return random1 + SeparatorString<String>() + copy;
}
template<class String>
- String operator_plus_equal_aliasing_cstr(String & test)
+ String append_cstr_number()
{
// 21.3.5
- const typename String::size_type offset = random(0, test.size());
- test += test.c_str() + offset;
- return test;
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type number = random(0, random2.size());
+ random1.append(random2.c_str(), number);
+ return random1;
}
template<class String>
- String operator_plus_equal_char(String & test)
+ String append_cstr_number__self()
{
// 21.3.5
- test += random('a', 'z');
- return test;
+ String random1(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type number = random(0, random1.size());
+ random1.append(random1.c_str(), number);
+ return random1;
}
template<class String>
- String append_string(String & test)
+ String append_cstr_number__selfcopy()
{
// 21.3.5
- String str(RandomString<String>(MaxString<String>::value));
- test.append(str);
- return test;
+ String random1(RandomString<String>(MaxString<String>::value));
+ String copy(random1);
+ const typename String::size_type number = random(0, random1.size());
+ random1.append(copy.c_str(), number);
+ return random1 + SeparatorString<String>() + copy;
}
template<class String>
- String append_string_start_range(String & test)
+ String append_cstr()
{
// 21.3.5
- String s(RandomString<String>(MaxString<String>::value));
- const typename String::size_type start = random(0, s.size());
- const typename String::size_type range = random(0, MaxString<String>::value);
- test.append(s, start, range);
- return test;
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ random1.append(random2.c_str());
+ return random1;
}
template<class String>
- String append_cstr_size(String & test)
+ String append_cstr__self()
{
// 21.3.5
- String s(RandomString<String>(MaxString<String>::value));
- const typename String::size_type size = random(0, s.size());
- test.append(s.c_str(), size);
- return test;
+ String random1(RandomString<String>(MaxString<String>::value));
+ random1.append(random1.c_str());
+ return random1;
}
template<class String>
- String append_cstr(String & test)
+ String append_cstr__selfcopy()
{
// 21.3.5
- String str(RandomString<String>(MaxString<String>::value));
- test.append(str.c_str());
- return test;
+ String random1(RandomString<String>(MaxString<String>::value));
+ String copy(random1);
+ random1.append(copy.c_str());
+ return random1 + SeparatorString<String>() + copy;
}
template<class String>
- String append_count_char(String & test)
+ String append_number_char()
{
// 21.3.5
- const typename String::size_type count = random(0, MaxString<String>::value);
+ String random1(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type number = random(0, MaxString<String>::value);
const typename String::value_type value = random('a', 'z');
- test.append(count, value);
- return test;
+ random1.append(number, value);
+ return random1;
}
template<class String>
- String append_iterators(String & test)
+ String append_iterator_iterator()
{
// 21.3.5
- std::list<typename String::value_type> lst(RandomList<String>(MaxString<String>::value));
- test.append(lst.begin(), lst.end());
- return test;
+ String random1(RandomString<String>(MaxString<String>::value));
+ std::list<typename String::value_type> list(RandomList<String>(MaxString<String>::value));
+ random1.append(list.begin(), list.end());
+ return random1;
}
template<class String>
- String push_back_char(String & test)
+ String append_iterator_iterator__self()
{
// 21.3.5
+ String random1(RandomString<String>(MaxString<String>::value));
+ random1.append(random1.begin(), random1.end());
+ return random1;
+ }
+
+ template<class String>
+ String append_iterator_iterator__selfcopy()
+ {
+ // 21.3.5
+ String random1(RandomString<String>(MaxString<String>::value));
+ String copy(random1);
+ random1.append(copy.begin(), copy.end());
+ return random1 + SeparatorString<String>() + copy;
+ }
+
+ template<class String>
+ String append_iterator_iterator__self_reverse()
+ {
+ // 21.3.5
+ String random1(RandomString<String>(MaxString<String>::value));
+ random1.append(random1.rbegin(), random1.rend());
+ return random1;
+ }
+
+ template<class String>
+ String append_iterator_iterator__selfcopy_reverse()
+ {
+ // 21.3.5
+ String random1(RandomString<String>(MaxString<String>::value));
+ String copy(random1);
+ random1.append(copy.rbegin(), copy.rend());
+ return random1 + SeparatorString<String>() + copy;
+ }
+
+ template<class String>
+ String push_back_char()
+ {
+ // 21.3.5
+ String random1(RandomString<String>(MaxString<String>::value));
const typename String::value_type value = random('a', 'z');
- test.push_back(value);
- return test;
+ random1.push_back(value);
+ return random1;
}
template<class String>
- String assign_string(String & test)
+ String assign_string()
{
// 21.3.5
- String str(RandomString<String>(MaxString<String>::value));
- test.assign(str);
- return test;
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ random1.assign(random2);
+ return random1 + SeparatorString<String>() + random2;
}
template<class String>
- String assign_string_start_size(String & test)
+ String assign_string__self()
{
// 21.3.5
- String str(RandomString<String>(MaxString<String>::value));
- const typename String::size_type start = random(0, str.size());
- const typename String::size_type size = random(0, MaxString<String>::value);
- test.assign(str, start, size);
- return test;
+ String random1(RandomString<String>(MaxString<String>::value));
+ random1.assign(random1);
+ return random1;
}
template<class String>
- String assign_cstr_size(String & test)
+ String assign_string__selfcopy()
{
// 21.3.5
- String str(RandomString<String>(MaxString<String>::value));
- const typename String::size_type size = random(0, str.size());
- test.assign(str.c_str(), size);
- return test;
+ String random1(RandomString<String>(MaxString<String>::value));
+ String copy(random1);
+ random1.assign(copy);
+ return random1 + SeparatorString<String>() + copy;
}
template<class String>
- String assign_cstr(String & test)
+ String assign_string_position_number()
{
// 21.3.5
- String str(RandomString<String>(MaxString<String>::value));
- test.assign(str.c_str());
- return test;
+ String random1(RandomString<String>(MaxString<String>::value));
+ const String random2(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type position = random(0, random2.size());
+ const typename String::size_type number = random(0, MaxString<String>::value);
+ random1.assign(random2, position, number);
+ return random1 + SeparatorString<String>() + random2;
}
template<class String>
- String assign_number_char(String & test)
+ String assign_string_position_number__self()
{
// 21.3.5
+ String random1(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type position = random(0, random1.size());
const typename String::size_type number = random(0, MaxString<String>::value);
+ random1.assign(random1, position, number);
+ return random1;
+ }
+
+ template<class String>
+ String assign_string_position_number__selfcopy()
+ {
+ // 21.3.5
+ String random1(RandomString<String>(MaxString<String>::value));
+ const String copy(random1);
+ const typename String::size_type position = random(0, random1.size());
+ const typename String::size_type number = random(0, MaxString<String>::value);
+ random1.assign(copy, position, number);
+ return random1 + SeparatorString<String>() + copy;
+ }
+
+ template<class String>
+ String assign_cstr_number()
+ {
+ // 21.3.5
+ String random1(RandomString<String>(MaxString<String>::value));
+ const String random2(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type number = random(0, random2.size());
+ random1.assign(random2.c_str(), number);
+ return random1;
+ }
+
+ template<class String>
+ String assign_cstr_number__self()
+ {
+ // 21.3.5
+ String random1(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type number = random(0, random1.size());
+ random1.assign(random1.c_str(), number);
+ return random1;
+ }
+
+ template<class String>
+ String assign_cstr_number__selfcopy()
+ {
+ // 21.3.5
+ String random1(RandomString<String>(MaxString<String>::value));
+ const String copy(random1);
+ const typename String::size_type number = random(0, copy.size());
+ random1.assign(copy.c_str(), number);
+ return random1 + SeparatorString<String>() + copy;
+ }
+
+ template<class String>
+ String assign_cstr()
+ {
+ // 21.3.5
+ String random1(RandomString<String>(MaxString<String>::value));
+ const String random2(RandomString<String>(MaxString<String>::value));
+ random1.assign(random2.c_str());
+ return random1 + SeparatorString<String>() + random2;
+ }
+
+ template<class String>
+ String assign_cstr__self()
+ {
+ // 21.3.5
+ String random1(RandomString<String>(MaxString<String>::value));
+ random1.assign(random1.c_str());
+ return random1;
+ }
+
+ template<class String>
+ String assign_cstr__selfcopy()
+ {
+ // 21.3.5
+ String random1(RandomString<String>(MaxString<String>::value));
+ const String copy(random1);
+ random1.assign(copy.c_str());
+ return random1 + SeparatorString<String>() + copy;
+ }
+
+ template<class String>
+ String assign_number_char()
+ {
+ // 21.3.5
+ String random1(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type number = random(0, MaxString<String>::value);
const typename String::value_type value = random('a', 'z');
- test.assign(number, value);
- return test;
+ random1.assign(number, value);
+ return random1;
}
template<class String>
- String assign_iterators(String & test)
+ String assign_iterator_iterator()
{
// 21.3.5
- std::list<typename String::value_type> lst(RandomList<String>(MaxString<String>::value));
- test.assign(lst.begin(), lst.end());
- return test;
+ String random1(RandomString<String>(MaxString<String>::value));
+ std::list<typename String::value_type> list(RandomList<String>(MaxString<String>::value));
+ random1.assign(list.begin(), list.end());
+ return random1;
}
template<class String>
- String insert_position_string(String & test)
+ String assign_iterator_iterator__self()
{
// 21.3.5
- const typename String::size_type position = random(0, test.size());
- String str(RandomString<String>(MaxString<String>::value));
- test.insert(position, str);
- return test;
+ String random1(RandomString<String>(MaxString<String>::value));
+ random1.assign(random1.begin(), random1.end());
+ return random1;
}
template<class String>
- String insert_position_string_start_end(String & test)
+ String assign_iterator_iterator__selfcopy()
{
// 21.3.5
- String str(RandomString<String>(MaxString<String>::value));
- const typename String::size_type position = random(0, test.size());
- const typename String::size_type start = random(0, str.size());
- const typename String::size_type end = random(0, MaxString<String>::value);
- test.insert(position, str, start, end);
- return test;
+ String random1(RandomString<String>(MaxString<String>::value));
+ String copy(random1);
+ random1.assign(copy.begin(), copy.end());
+ return random1 + SeparatorString<String>() + copy;
}
template<class String>
- String insert_position_cstr_size(String & test)
+ String assign_iterator_iterator__self_reverse()
{
// 21.3.5
- String str(RandomString<String>(MaxString<String>::value));
- const typename String::size_type position = random(0, test.size());
- const typename String::size_type size = random(0, str.size());
- test.insert(position, str.c_str(), size);
- return test;
+ String random1(RandomString<String>(MaxString<String>::value));
+ random1.assign(random1.rbegin(), random1.rend());
+ return random1;
}
template<class String>
- String insert_position_cstr(String & test)
+ String assign_iterator_iterator__selfcopy_reverse()
{
// 21.3.5
- const typename String::size_type position = random(0, test.size());
- String str(RandomString<String>(MaxString<String>::value));
- test.insert(position, str.c_str());
- return test;
+ String random1(RandomString<String>(MaxString<String>::value));
+ String copy(random1);
+ random1.assign(copy.rbegin(), copy.rend());
+ return random1 + SeparatorString<String>() + copy;
}
template<class String>
- String insert_position_number_char(String & test)
+ String insert_position_string()
{
// 21.3.5
- const typename String::size_type position = random(0, test.size());
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type position = random(0, random1.size());
+ random1.insert(position, random2);
+ return random1 + SeparatorString<String>() + random2;
+ }
+
+ template<class String>
+ String insert_position_string__self()
+ {
+ // 21.3.5
+ String random1(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type position = random(0, random1.size());
+ random1.insert(position, random1);
+ return random1;
+ }
+
+ template<class String>
+ String insert_position_string__selfcopy()
+ {
+ // 21.3.5
+ String random1(RandomString<String>(MaxString<String>::value));
+ String copy(random1);
+ const typename String::size_type position = random(0, random1.size());
+ random1.insert(position, copy);
+ return random1 + SeparatorString<String>() + copy;
+ }
+
+ template<class String>
+ String insert_position_string_position_number()
+ {
+ // 21.3.5
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type position1 = random(0, random1.size());
+ const typename String::size_type position2 = random(0, random2.size());
const typename String::size_type number = random(0, MaxString<String>::value);
+ random1.insert(position1, random2, position2, number);
+ return random1 + SeparatorString<String>() + random2;
+ }
+
+ template<class String>
+ String insert_position_string_position_number__self()
+ {
+ // 21.3.5
+ String random1(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type position1 = random(0, random1.size());
+ const typename String::size_type position2 = random(0, random1.size());
+ const typename String::size_type number = random(0, MaxString<String>::value);
+ random1.insert(position1, random1, position2, number);
+ return random1;
+ }
+
+ template<class String>
+ String insert_position_string_position_number__selfcopy()
+ {
+ // 21.3.5
+ String random1(RandomString<String>(MaxString<String>::value));
+ String copy(random1);
+ const typename String::size_type position1 = random(0, random1.size());
+ const typename String::size_type position2 = random(0, copy.size());
+ const typename String::size_type number = random(0, MaxString<String>::value);
+ random1.insert(position1, copy, position2, number);
+ return random1 + SeparatorString<String>() + copy;
+ }
+
+ template<class String>
+ String insert_position_cstr_number()
+ {
+ // 21.3.5
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type position = random(0, random1.size());
+ const typename String::size_type number = random(0, random2.size());
+ random1.insert(position, random2.c_str(), number);
+ return random1 + SeparatorString<String>() + random2;
+ }
+
+ template<class String>
+ String insert_position_cstr_number__self()
+ {
+ // 21.3.5
+ String random1(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type position = random(0, random1.size());
+ const typename String::size_type number = random(0, random1.size());
+ random1.insert(position, random1.c_str(), number);
+ return random1;
+ }
+
+ template<class String>
+ String insert_position_cstr_number__selfcopy()
+ {
+ // 21.3.5
+ String random1(RandomString<String>(MaxString<String>::value));
+ String copy(random1);
+ const typename String::size_type position = random(0, random1.size());
+ const typename String::size_type number = random(0, copy.size());
+ random1.insert(position, copy.c_str(), number);
+ return random1 + SeparatorString<String>() + copy;
+ }
+
+ template<class String>
+ String insert_position_cstr()
+ {
+ // 21.3.5
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type position = random(0, random1.size());
+ random1.insert(position, random2.c_str());
+ return random1 + SeparatorString<String>() + random2;
+ }
+
+ template<class String>
+ String insert_position_cstr__self()
+ {
+ // 21.3.5
+ String random1(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type position = random(0, random1.size());
+ random1.insert(position, random1.c_str());
+ return random1;
+ }
+
+ template<class String>
+ String insert_position_cstr__selfcopy()
+ {
+ // 21.3.5
+ String random1(RandomString<String>(MaxString<String>::value));
+ String copy(random1);
+ const typename String::size_type position = random(0, random1.size());
+ random1.insert(position, copy.c_str());
+ return random1 + SeparatorString<String>() + copy;
+ }
+
+ template<class String>
+ String insert_iterator_char()
+ {
+ // 21.3.5
+ String random1(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type position = random(0, random1.size());
const typename String::value_type value = random('a', 'z');
- test.insert(position, number, value);
- return test;
+ random1.insert(random1.begin() + position, value);
+ return random1;
}
template<class String>
- String insert_iterator_char(String & test)
+ String insert_position_number_char()
{
// 21.3.5
- const typename String::size_type offset = random(0, test.size());
+ String random1(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type position = random(0, random1.size());
+ const typename String::size_type number = random(0, MaxString<String>::value);
const typename String::value_type value = random('a', 'z');
- test.insert(test.begin() + offset, value);
- return test;
+ random1.insert(position, number, value);
+ return random1;
}
template<class String>
- String insert_iterator_iterator_range(String & test)
+ String insert_iterator_iterator()
{
// 21.3.5
- std::list<typename String::value_type> lst(RandomList<String>(MaxString<String>::value));
- const typename String::size_type offset = random(0, test.size());
- test.insert(test.begin() + offset, lst.begin(), lst.end());
- return test;
+ String random1(RandomString<String>(MaxString<String>::value));
+ std::list<typename String::value_type> list(RandomList<String>(MaxString<String>::value));
+ const typename String::size_type position = random(0, random1.size());
+ random1.insert(random1.begin() + position, list.begin(), list.end());
+ return random1;
}
template<class String>
- String erase_position_position(String & test)
+ String insert_iterator_iterator__self()
{
// 21.3.5
- const typename String::size_type start = random(0, test.size());
+ String random1(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type position = random(0, random1.size());
+ random1.insert(random1.begin() + position, random1.begin(), random1.end());
+ return random1;
+ }
+
+ template<class String>
+ String insert_iterator_iterator__selfcopy()
+ {
+ // 21.3.5
+ String random1(RandomString<String>(MaxString<String>::value));
+ String copy(random1);
+ const typename String::size_type position = random(0, random1.size());
+ random1.insert(random1.begin() + position, copy.begin(), copy.end());
+ return random1;
+ }
+
+ template<class String>
+ String insert_iterator_iterator__self_reverse()
+ {
+ // 21.3.5
+ String random1(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type position = random(0, random1.size());
+ random1.insert(random1.begin() + position, random1.rbegin(), random1.rend());
+ return random1;
+ }
+
+ template<class String>
+ String insert_iterator_iterator__selfcopy_reverse()
+ {
+ // 21.3.5
+ String random1(RandomString<String>(MaxString<String>::value));
+ String copy(random1);
+ const typename String::size_type position = random(0, random1.size());
+ random1.insert(random1.begin() + position, copy.rbegin(), copy.rend());
+ return random1;
+ }
+
+ template<class String>
+ String erase_position_number()
+ {
+ // 21.3.5
+ String random1(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type start = random(0, random1.size());
const typename String::size_type end = random(0, MaxString<String>::value);
- test.erase(start, end);
- return test;
+ random1.erase(start, end);
+ return random1;
}
template<class String>
- String erase_iterator(String & test)
+ String erase_iterator()
{
// 21.3.5
- if(!test.empty())
+ String random1(RandomString<String>(MaxString<String>::value));
+ if(!random1.empty())
{
- const typename String::size_type offset = random(0, test.size());
- test.erase(test.begin() + offset);
+ const typename String::size_type position = random(0, random1.size());
+ random1.erase(random1.begin() + position);
}
- return test;
+ return random1;
}
template<class String>
- String erase_iterator_iterator(String & test)
+ String erase_iterator_iterator()
{
// 21.3.5
- const typename String::size_type offset = random(0, test.size());
- const typename String::iterator i = test.begin() + offset;
- const typename String::size_type endOffset = random(0, test.end() - i);
- test.erase(i, i + endOffset);
- return test;
+ String random1(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type position1 = random(0, random1.size());
+ const typename String::size_type position2 = random(position1, random1.size());
+ random1.erase(random1.begin() + position1, random1.begin() + position2);
+ return random1;
}
template<class String>
- String replace_start_end_copyself(String & test)
+ String replace_position_number_string()
{
// 21.3.5
- const typename String::size_type pos = random(0, test.size());
- const typename String::size_type end = random(0, test.size() - pos);
- test.replace(pos, end, String(test));
- return test;
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type position = random(0, random1.size());
+ const typename String::size_type number = random(0, MaxString<String>::value);
+ random1.replace(position, number, random2);
+ return random1;
}
template<class String>
- String replace_start_end_self(String & test)
+ String replace_position_number_string__self()
{
// 21.3.5
- const typename String::size_type pos = random(0, test.size());
- const typename String::size_type end = random(0, test.size() - pos);
- test.replace(pos, end, test);
- return test;
+ String random1(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type position = random(0, random1.size());
+ const typename String::size_type number = random(0, MaxString<String>::value);
+ random1.replace(position, number, random1);
+ return random1;
}
template<class String>
- String replace_start_end_string(String & test)
+ String replace_position_number_string__selfcopy()
{
// 21.3.5
- const typename String::size_type pos = random(0, test.size());
- const typename String::size_type end = random(0, test.size() - pos);
- String str(RandomString<String>(MaxString<String>::value));
- test.replace(pos, pos + end, str);
- return test;
+ String random1(RandomString<String>(MaxString<String>::value));
+ String copy(random1);
+ const typename String::size_type position = random(0, random1.size());
+ const typename String::size_type number = random(0, MaxString<String>::value);
+ random1.replace(position, number, copy);
+ return random1;
}
template<class String>
- String replace_start_end_selfcopy_start_end(String & test)
+ String replace_position_number_string_position_number()
{
// 21.3.5
- const typename String::size_type pos1 = random(0, test.size());
- const typename String::size_type pos2 = random(0, test.size());
- const typename String::size_type offset1 = random(0, test.size() - pos1);
- const typename String::size_type offset2 = random(0, test.size() - pos2);
- test.replace(pos1, pos1 + offset1, String(test), pos2, pos2 + offset2);
- return test;
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type position1 = random(0, random1.size());
+ const typename String::size_type number1 = random(0, MaxString<String>::value);
+ const typename String::size_type position2 = random(0, random2.size());
+ const typename String::size_type number2 = random(0, MaxString<String>::value);
+ random1.replace(position1, number1, random2, position2, number2);
+ return random1;
}
template<class String>
- String replace_start_end_self_start_end(String & test)
+ String replace_position_number_string_position_number__self()
{
// 21.3.5
- const typename String::size_type pos1 = random(0, test.size());
- const typename String::size_type pos2 = random(0, test.size());
- const typename String::size_type offset1 = random(0, test.size() - pos1);
- const typename String::size_type offset2 = random(0, test.size() - pos2);
- test.replace(pos1, pos1 + offset1, test, pos2, pos2 + offset2);
- return test;
+ String random1(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type position1 = random(0, random1.size());
+ const typename String::size_type number1 = random(0, MaxString<String>::value);
+ const typename String::size_type position2 = random(0, random1.size());
+ const typename String::size_type number2 = random(0, MaxString<String>::value);
+ random1.replace(position1, number1, random1, position2, number2);
+ return random1;
}
template<class String>
- String replace_start_end_string_start_end(String & test)
+ String replace_position_number_string_position_number__selfcopy()
{
// 21.3.5
- String str(RandomString<String>(MaxString<String>::value));
- const typename String::size_type pos1 = random(0, test.size());
- const typename String::size_type pos2 = random(0, str.size());
- const typename String::size_type offset1 = random(0, test.size() - pos1);
- const typename String::size_type offset2 = random(0, str.size() - pos2);
- test.replace(pos1, pos1 + offset1, str, pos2, pos2 + offset2);
- return test;
+ String random1(RandomString<String>(MaxString<String>::value));
+ String copy(random1);
+ const typename String::size_type position1 = random(0, random1.size());
+ const typename String::size_type number1 = random(0, MaxString<String>::value);
+ const typename String::size_type position2 = random(0, random1.size());
+ const typename String::size_type number2 = random(0, MaxString<String>::value);
+ random1.replace(position1, number1, copy, position2, number2);
+ return random1;
}
template<class String>
- String replace_start_end_selfcopycstr_size(String & test)
+ String replace_position_number_cstr_number()
{
// 21.3.5
- const typename String::size_type pos = random(0, test.size());
- const typename String::size_type pos2 = random(0, test.size() - pos);
- test.replace(pos, pos2, String(test).c_str(), test.size());
- return test;
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type position1 = random(0, random1.size());
+ const typename String::size_type number1 = random(0, MaxString<String>::value);
+ const typename String::size_type number2 = random(0, random2.size());
+ random1.replace(position1, number1, random2.c_str(), number2);
+ return random1;
}
template<class String>
- String replace_start_end_selfcstr_size(String & test)
+ String replace_position_number_cstr_number__self()
{
// 21.3.5
- const typename String::size_type pos = random(0, test.size());
- const typename String::size_type pos2 = random(0, test.size() - pos);
- test.replace(pos, pos2, test.c_str(), test.size());
- return test;
+ String random1(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type position1 = random(0, random1.size());
+ const typename String::size_type number1 = random(0, MaxString<String>::value);
+ const typename String::size_type number2 = random(0, random1.size());
+ random1.replace(position1, number1, random1.c_str(), number2);
+ return random1;
}
template<class String>
- String replace_start_end_stringcstr_size(String & test)
+ String replace_position_number_cstr_number__selfcopy()
{
// 21.3.5
- String str(RandomString<String>(MaxString<String>::value));
- const typename String::size_type pos = random(0, test.size());
- const typename String::size_type offset = random(0, test.size() - pos);
- test.replace(pos, pos + offset, str.c_str(), str.size());
- return test;
+ String random1(RandomString<String>(MaxString<String>::value));
+ String copy(random1);
+ const typename String::size_type position1 = random(0, random1.size());
+ const typename String::size_type number1 = random(0, MaxString<String>::value);
+ const typename String::size_type number2 = random(0, copy.size());
+ random1.replace(position1, number1, copy.c_str(), ...
[truncated message content] |
|
From: <jfb...@us...> - 2009-03-05 22:05:00
|
Revision: 1001
http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1001&view=rev
Author: jfbastien
Date: 2009-03-05 22:04:56 +0000 (Thu, 05 Mar 2009)
Log Message:
-----------
Bug #2666059: cap buffer size to 126.
Modified Paths:
--------------
trunk/include/loki/flex/smallstringopt.h
Modified: trunk/include/loki/flex/smallstringopt.h
===================================================================
--- trunk/include/loki/flex/smallstringopt.h 2009-03-05 21:12:02 UTC (rev 1000)
+++ trunk/include/loki/flex/smallstringopt.h 2009-03-05 22:04:56 UTC (rev 1001)
@@ -31,7 +31,7 @@
typedef @ const_iterator;
typedef A allocator_type;
typedef @ size_type;
-
+
StoragePolicy(const StoragePolicy& s);
StoragePolicy(const A&);
StoragePolicy(const E* s, size_type len, const A&);
@@ -42,7 +42,7 @@
const_iterator begin() const;
iterator end();
const_iterator end() const;
-
+
size_type size() const;
size_type max_size() const;
size_type capacity() const;
@@ -50,17 +50,17 @@
void reserve(size_type res_arg);
void append(const E* s, size_type sz);
-
+
template <class InputIterator>
void append(InputIterator b, InputIterator e);
void resize(size_type newSize, E fill);
void swap(StoragePolicy& rhs);
-
+
const E* c_str() const;
const E* data() const;
-
+
A get_allocator() const;
};
////////////////////////////////////////////////////////////////////////////////
@@ -74,12 +74,24 @@
#include <stdexcept>
#include "flex_string_details.h"
+namespace SmallStringOptImpl
+{
+ // The threshold for SmallStringOpt cannot be greater than 126. See Loki bug #2666059 for more details:
+ // https://sourceforge.net/tracker2/?func=detail&aid=2666059&group_id=29557&atid=396644
+ template<int Expression> struct BufferSizeCannotBeGreaterThan126;
+ template<> struct BufferSizeCannotBeGreaterThan126<true> { };
+
+#define LOKI_FLEX_STRING_BUFFERSIZECANNOTBEGREATERTHAN126(expression) \
+ { SmallStringOptImpl::BufferSizeCannotBeGreaterThan126<((expression) != 0)> \
+ bufferSizeCannotBeGreaterThan126; (void)bufferSizeCannotBeGreaterThan126; }
+}
+
////////////////////////////////////////////////////////////////////////////////
// class template SmallStringOpt
// Builds the small string optimization over any other storage
////////////////////////////////////////////////////////////////////////////////
-template <class Storage, unsigned int threshold,
+template <class Storage, unsigned int threshold,
typename Align = typename Storage::value_type*>
class SmallStringOpt
{
@@ -90,54 +102,56 @@
typedef typename Storage::allocator_type allocator_type;
typedef typename allocator_type::size_type size_type;
typedef typename Storage::reference reference;
-
+
private:
- enum { temp1 = threshold * sizeof(value_type) > sizeof(Storage)
- ? threshold * sizeof(value_type)
+ enum { temp1 = threshold * sizeof(value_type) > sizeof(Storage)
+ ? threshold * sizeof(value_type)
: sizeof(Storage) };
-
+
enum { temp2 = temp1 > sizeof(Align) ? temp1 : sizeof(Align) };
public:
- enum { maxSmallString =
+ enum { maxSmallString =
(temp2 + sizeof(value_type) - 1) / sizeof(value_type) };
-
+
private:
enum { magic = maxSmallString + 1 };
-
+
union
{
mutable value_type buf_[maxSmallString + 1];
Align align_;
};
-
+
Storage& GetStorage()
{
assert(buf_[maxSmallString] == magic);
Storage* p = reinterpret_cast<Storage*>(&buf_[0]);
return *p;
}
-
+
const Storage& GetStorage() const
{
assert(buf_[maxSmallString] == magic);
const Storage *p = reinterpret_cast<const Storage*>(&buf_[0]);
return *p;
}
-
+
bool Small() const
{
return buf_[maxSmallString] != magic;
}
-
+
public:
- SmallStringOpt(const SmallStringOpt& s)
+ SmallStringOpt(const SmallStringOpt& s)
{
+ LOKI_FLEX_STRING_BUFFERSIZECANNOTBEGREATERTHAN126(maxSmallString <= 126)
+
if (s.Small())
{
flex_string_details::pod_copy(
- s.buf_,
- s.buf_ + s.size(),
+ s.buf_,
+ s.buf_ + s.size(),
buf_);
}
else
@@ -146,12 +160,12 @@
}
buf_[maxSmallString] = s.buf_[maxSmallString];
}
-
+
SmallStringOpt(const allocator_type&)
{
buf_[maxSmallString] = maxSmallString;
}
-
+
SmallStringOpt(const value_type* s, size_type len, const allocator_type& a)
{
if (len <= maxSmallString)
@@ -179,7 +193,7 @@
buf_[maxSmallString] = magic;
}
}
-
+
// Fix suggested by Andrew Barnert on 07/03/2007
SmallStringOpt& operator=(const SmallStringOpt& rhs)
{
@@ -228,32 +242,32 @@
iterator begin()
{
if (Small()) return buf_;
- return &*GetStorage().begin();
+ return &*GetStorage().begin();
}
-
+
const_iterator begin() const
{
if (Small()) return buf_;
- return &*GetStorage().begin();
+ return &*GetStorage().begin();
}
-
+
iterator end()
{
if (Small()) return buf_ + maxSmallString - buf_[maxSmallString];
- return &*GetStorage().end();
+ return &*GetStorage().end();
}
-
+
const_iterator end() const
{
if (Small()) return buf_ + maxSmallString - buf_[maxSmallString];
- return &*GetStorage().end();
+ return &*GetStorage().end();
}
-
+
size_type size() const
{
assert(!Small() || maxSmallString >= buf_[maxSmallString]);
- return Small()
- ? maxSmallString - buf_[maxSmallString]
+ return Small()
+ ? maxSmallString - buf_[maxSmallString]
: GetStorage().size();
}
@@ -270,7 +284,7 @@
if (res_arg <= maxSmallString) return;
SmallStringOpt temp(*this);
this->~SmallStringOpt();
- new(buf_) Storage(temp.data(), temp.size(),
+ new(buf_) Storage(temp.data(), temp.size(),
temp.get_allocator());
buf_[maxSmallString] = magic;
GetStorage().reserve(res_arg);
@@ -281,7 +295,7 @@
}
assert(capacity() >= res_arg);
}
-
+
template <class FwdIterator>
void append(FwdIterator b, FwdIterator e)
{
@@ -292,7 +306,7 @@
else
{
// append to a small string
- const size_type
+ const size_type
sz = std::distance(b, e),
neededCapacity = maxSmallString - buf_[maxSmallString] + sz;
@@ -325,7 +339,7 @@
// Small string resized to big string
SmallStringOpt temp(*this); // can't throw
// 11-17-2001: correct exception safety bug
- Storage newString(temp.data(), temp.size(),
+ Storage newString(temp.data(), temp.size(),
temp.get_allocator());
newString.resize(n, c);
// We make the reasonable assumption that an empty Storage
@@ -379,7 +393,7 @@
if (rhs.Small())
{
// Small swapped with small
- std::swap_ranges(buf_, buf_ + maxSmallString + 1,
+ std::swap_ranges(buf_, buf_ + maxSmallString + 1,
rhs.buf_);
}
else
@@ -415,17 +429,17 @@
}
}
}
-
+
const value_type* c_str() const
- {
- if (!Small()) return GetStorage().c_str();
+ {
+ if (!Small()) return GetStorage().c_str();
buf_[maxSmallString - buf_[maxSmallString]] = value_type();
return buf_;
}
const value_type* data() const
{ return Small() ? buf_ : GetStorage().data(); }
-
+
allocator_type get_allocator() const
{ return allocator_type(); }
};
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jfb...@us...> - 2009-03-05 21:12:09
|
Revision: 1000
http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1000&view=rev
Author: jfbastien
Date: 2009-03-05 21:12:02 +0000 (Thu, 05 Mar 2009)
Log Message:
-----------
Cache call to size() in find(): it wasn't being optimized out.
Modified Paths:
--------------
trunk/include/loki/flex/flex_string_shell.h
Modified: trunk/include/loki/flex/flex_string_shell.h
===================================================================
--- trunk/include/loki/flex/flex_string_shell.h 2009-03-05 21:09:20 UTC (rev 999)
+++ trunk/include/loki/flex/flex_string_shell.h 2009-03-05 21:12:02 UTC (rev 1000)
@@ -896,9 +896,10 @@
size_type find (const value_type* s, size_type pos, size_type n) const
{
- if (n + pos > size())
+ const size_type size(size());
+ if (n + pos > size)
return npos;
- for (; pos + n <= size(); ++pos)
+ for (; pos + n <= size; ++pos)
{
if (traits_type::compare(data() + pos, s, n) == 0)
{
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jfb...@us...> - 2009-03-05 21:09:24
|
Revision: 999
http://loki-lib.svn.sourceforge.net/loki-lib/?rev=999&view=rev
Author: jfbastien
Date: 2009-03-05 21:09:20 +0000 (Thu, 05 Mar 2009)
Log Message:
-----------
Add a small string optimization test with a buffer of 126.
Cache size() outside the loop for RandomString.
Modify Num2String so that npos is properly taken into account.
Add Tristate2String.
Modify seedForThisIteration so that its value is count + rand() instead of just rand(): using just rand meant that a lot of the initial seeds repeated because the pseudo-randomness of rand isn't good. Adding count should somewhat reduce the repetitions.
I'd consider using another random number generator, rand() is slow and has a bad distribution.
Modified Paths:
--------------
trunk/test/flex_string/main.cpp
Modified: trunk/test/flex_string/main.cpp
===================================================================
--- trunk/test/flex_string/main.cpp 2009-03-05 16:13:57 UTC (rev 998)
+++ trunk/test/flex_string/main.cpp 2009-03-05 21:09:20 UTC (rev 999)
@@ -83,6 +83,13 @@
char,
std::char_traits<char>,
std::allocator<char>,
+ SmallStringOpt<SimpleStringStorage<char, std::allocator<char> >, 126>
+ > my_string_SmallStringSimpleBigBuffer;
+
+ typedef flex_string<
+ char,
+ std::char_traits<char>,
+ std::allocator<char>,
SmallStringOpt<VectorStringStorage<char, std::allocator<char> >, 23>
> my_string_SmallStringVector;
@@ -119,13 +126,20 @@
const typename String::size_type size = random(0, maxSize);
String result(size, '\0');
size_t i = 0;
- for (; i != result.size(); ++i)
+ for (; i != size; ++i)
{
result[i] = random('a', 'z');
}
return result;
}
+// Specialize this method for different String types.
+template<class String>
+String Npos()
+{
+ return "{npos}";
+}
+
template<class String, class Integral>
String Num2String(Integral value)
{
@@ -136,6 +150,37 @@
}
template<class String>
+String Num2String(typename String::size_type value)
+{
+ if(String::npos != value)
+ {
+ typedef typename String::value_type CharType;
+ std::basic_ostringstream<CharType, std::char_traits<CharType>, std::allocator<CharType> > stream;
+ stream << value;
+ return stream.str().c_str();
+ }
+ else
+ {
+ // Not all strings will have the same value for npos.
+ // Since methods like find return npos on failure we want to represent npos in an implementation-independent manner.
+ return Npos<String>();
+ }
+}
+
+// Some comparison functions return 0 or a value greater/smaller than zero.
+// This function makes the greater/smaller than zero specification implementation-independent.
+template<class String>
+String Tristate2String(int tristate)
+{
+ if(0 == tristate)
+ return Num2String<String>(0);
+ else if(0 < tristate)
+ return Num2String<String>(1);
+ else
+ return Num2String<String>(2);
+}
+
+template<class String>
std::list<typename String::value_type> RandomList(typename String::size_type maxSize)
{
const typename String::size_type size = random(0, maxSize);
@@ -1308,10 +1353,7 @@
String compare_selfcopy(String & test)
{
int tristate = test.compare(String(test));
- if (tristate > 0) tristate = 1;
- else if (tristate < 0) tristate = 2;
- test = Num2String<String>(tristate);
- return test;
+ return Tristate2String<String>(tristate);
}
template<class String>
@@ -1319,10 +1361,7 @@
{
String str(RandomString<String>(MaxString<String>::value));
int tristate = test.compare(str);
- if (tristate > 0) tristate = 1;
- else if (tristate < 0) tristate = 2;
- test = Num2String<String>(tristate);
- return test;
+ return Tristate2String<String>(tristate);
}
template<class String>
@@ -1331,10 +1370,7 @@
const typename String::size_type index = random(0, test.size());
const typename String::size_type length = random(0, test.size());
int tristate = test.compare(index, length, String(test));
- if (tristate > 0) tristate = 1;
- else if (tristate < 0) tristate = 2;
- test = Num2String<String>(tristate);
- return test;
+ return Tristate2String<String>(tristate);
}
template<class String>
@@ -1344,10 +1380,7 @@
const typename String::size_type length = random(0, test.size());
String str(RandomString<String>(MaxString<String>::value));
int tristate = test.compare(index, length, str);
- if (tristate > 0) tristate = 1;
- else if (tristate < 0) tristate = 2;
- test = Num2String<String>(tristate);
- return test;
+ return Tristate2String<String>(tristate);
}
template<class String>
@@ -1359,10 +1392,7 @@
const typename String::size_type index2 = random(0, str.size());
const typename String::size_type length2 = random(0, str.size());
int tristate = test.compare(index, length, str, index2, length2);
- if (tristate > 0) tristate = 1;
- else if (tristate < 0) tristate = 2;
- test = Num2String<String>(tristate);
- return test;
+ return Tristate2String<String>(tristate);
}
template<class String>
@@ -1374,10 +1404,7 @@
const typename String::size_type index2 = random(0, str.size());
const typename String::size_type length2 = random(0, str.size());
int tristate = test.compare(index, length, str, index2, length2);
- if (tristate > 0) tristate = 1;
- else if (tristate < 0) tristate = 2;
- test = Num2String<String>(tristate);
- return test;
+ return Tristate2String<String>(tristate);
}
template<class String>
@@ -1385,10 +1412,7 @@
{
String str(RandomString<String>(MaxString<String>::value));
int tristate = test.compare(str.c_str());
- if (tristate > 0) tristate = 1;
- else if (tristate < 0) tristate = 2;
- test = Num2String<String>(tristate);
- return test;
+ return Tristate2String<String>(tristate);
}
template<class String>
@@ -1399,10 +1423,7 @@
const typename String::size_type length = random(0, test.size());
const typename String::size_type index2 = random(0, str.size());
int tristate = test.compare(index, length, str.c_str(), index2);
- if (tristate > 0) tristate = 1;
- else if (tristate < 0) tristate = 2;
- test = Num2String<String>(tristate);
- return test;
+ return Tristate2String<String>(tristate);
}
template<class String>
@@ -1647,21 +1668,22 @@
size_t count = 0;
using namespace StringsToTest;
- TestFunctions<std::string> testFunctions_std;
- TestFunctions<my_string_SimpleStorage> testFunctions_SimpleStorage;
- TestFunctions<my_string_AllocatorStorage> testFunctions_AllocatorStorage;
- TestFunctions<my_string_MallocatorStorage> testFunctions_MallocatorStorage;
- TestFunctions<my_string_VectorStorage> testFunctions_VectorStorage;
- TestFunctions<my_string_SmallStringSimple> testFunctions_SmallStringSimple;
- TestFunctions<my_string_SmallStringVector> testFunctions_SmallStringVector;
- TestFunctions<my_string_CowSimple> testFunctions_CowSimple;
- TestFunctions<my_string_CowAllocator> testFunctions_CowAllocator;
+ TestFunctions<std::string> testFunctions_std;
+ TestFunctions<my_string_SimpleStorage> testFunctions_SimpleStorage;
+ TestFunctions<my_string_AllocatorStorage> testFunctions_AllocatorStorage;
+ TestFunctions<my_string_MallocatorStorage> testFunctions_MallocatorStorage;
+ TestFunctions<my_string_VectorStorage> testFunctions_VectorStorage;
+ TestFunctions<my_string_SmallStringSimple> testFunctions_SmallStringSimple;
+ TestFunctions<my_string_SmallStringSimpleBigBuffer> testFunctions_smallStringSimpleBigBuffer;
+ TestFunctions<my_string_SmallStringVector> testFunctions_SmallStringVector;
+ TestFunctions<my_string_CowSimple> testFunctions_CowSimple;
+ TestFunctions<my_string_CowAllocator> testFunctions_CowAllocator;
for (;;)
{
std::cout << ++count << '\r';
- const unsigned int seedForThisIteration = rand();
+ const unsigned int seedForThisIteration = count + rand();
srand(seedForThisIteration);
const std::string reference(Test<std::string>(count, testFunctions_std));
@@ -1698,6 +1720,12 @@
{
srand(seedForThisIteration);
+ const my_string_SmallStringSimpleBigBuffer tested(Test<my_string_SmallStringSimpleBigBuffer>(count, testFunctions_smallStringSimpleBigBuffer));
+ checkResults(reference, tested, testFunctions_smallStringSimpleBigBuffer, seedForThisIteration, count);
+ }
+
+ {
+ srand(seedForThisIteration);
const my_string_SmallStringVector tested(Test<my_string_SmallStringVector>(count, testFunctions_SmallStringVector));
checkResults(reference, tested, testFunctions_SmallStringVector, seedForThisIteration, count);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jfb...@us...> - 2009-03-05 16:14:07
|
Revision: 998
http://loki-lib.svn.sourceforge.net/loki-lib/?rev=998&view=rev
Author: jfbastien
Date: 2009-03-05 16:13:57 +0000 (Thu, 05 Mar 2009)
Log Message:
-----------
Use MaxString<String>::value instead of 1000.
Modified Paths:
--------------
trunk/test/flex_string/main.cpp
Modified: trunk/test/flex_string/main.cpp
===================================================================
--- trunk/test/flex_string/main.cpp 2009-03-05 12:21:52 UTC (rev 997)
+++ trunk/test/flex_string/main.cpp 2009-03-05 16:13:57 UTC (rev 998)
@@ -205,7 +205,7 @@
String assignment(String & test)
{
// 21.3.1
- const typename String::size_type size = random(0, 1000);
+ const typename String::size_type size = random(0, MaxString<String>::value);
String s(size, '\0');
typename String::size_type i = 0;
for (; i != s.size(); ++i)
@@ -220,7 +220,7 @@
String assignment_with_cstr(String & test)
{
// 21.3.1
- const typename String::size_type size = random(0, 1000);
+ const typename String::size_type size = random(0, MaxString<String>::value);
String s(size, '\0');
typename String::size_type i = 0;
for (; i != s.size(); ++i)
@@ -331,7 +331,7 @@
template<class String>
String reserve(String & test)
{
- const typename String::size_type reserveSize = random(0, 1000);
+ const typename String::size_type reserveSize = random(0, MaxString<String>::value);
test.reserve(reserveSize);
return test;
}
@@ -1718,7 +1718,7 @@
int main()
{
- const time_t initialSeed(1236182091 /*time(0)*/);
+ const time_t initialSeed(time(0));
srand(unsigned(initialSeed));
std::cout << "initial seed = " << initialSeed << "\n\n";
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jfb...@us...> - 2009-03-05 12:21:55
|
Revision: 997
http://loki-lib.svn.sourceforge.net/loki-lib/?rev=997&view=rev
Author: jfbastien
Date: 2009-03-05 12:21:52 +0000 (Thu, 05 Mar 2009)
Log Message:
-----------
Typo.
Modified Paths:
--------------
trunk/include/loki/flex/simplestringstorage.h
Modified: trunk/include/loki/flex/simplestringstorage.h
===================================================================
--- trunk/include/loki/flex/simplestringstorage.h 2009-03-04 16:04:41 UTC (rev 996)
+++ trunk/include/loki/flex/simplestringstorage.h 2009-03-05 12:21:52 UTC (rev 997)
@@ -103,7 +103,7 @@
{
// 11-17-2000: comment added:
// No need to allocate (capacity + 1) to
- // accomodate the terminating 0, because Data already
+ // accommodate the terminating 0, because Data already
// has one one character in there
pData_ = static_cast<Data*>(
malloc(sizeof(Data) + capacity * sizeof(E)));
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jfb...@us...> - 2009-03-04 16:04:48
|
Revision: 996
http://loki-lib.svn.sourceforge.net/loki-lib/?rev=996&view=rev
Author: jfbastien
Date: 2009-03-04 16:04:41 +0000 (Wed, 04 Mar 2009)
Log Message:
-----------
There were test failures in release (MSVC 9 with Multi-threaded DLL runtime library) because random and RandomString were called directly as arguments to functions. When this happened more than once in the same function there would sometimes be different results because the order of evaluation of function arguments isn't guaranteed.
Modified Paths:
--------------
trunk/test/flex_string/main.cpp
Modified: trunk/test/flex_string/main.cpp
===================================================================
--- trunk/test/flex_string/main.cpp 2009-03-04 07:13:07 UTC (rev 995)
+++ trunk/test/flex_string/main.cpp 2009-03-04 16:04:41 UTC (rev 996)
@@ -116,7 +116,8 @@
template<class String>
String RandomString(size_t maxSize)
{
- String result(random(0, maxSize), '\0');
+ const typename String::size_type size = random(0, maxSize);
+ String result(size, '\0');
size_t i = 0;
for (; i != result.size(); ++i)
{
@@ -137,7 +138,8 @@
template<class String>
std::list<typename String::value_type> RandomList(typename String::size_type maxSize)
{
- std::list<typename String::value_type> lst(random(0, maxSize));
+ const typename String::size_type size = random(0, maxSize);
+ std::list<typename String::value_type> lst(size);
std::list<typename String::value_type>::iterator i = lst.begin();
for (; i != lst.end(); ++i)
{
@@ -175,7 +177,8 @@
{
// 21.3.1
const typename String::size_type pos = random(0, test.size());
- String s(test, pos, random(0, test.size() - pos));
+ const typename String::size_type length = random(0, test.size() - pos);
+ String s(test, pos, length);
return s;
}
@@ -183,9 +186,8 @@
String constructor_with_cstr_and_size(String & test)
{
// 21.3.1
- const typename String::size_type
- pos = random(0, test.size()),
- n = random(0, test.size() - pos);
+ const typename String::size_type pos = random(0, test.size());
+ const typename String::size_type n = random(0, test.size() - pos);
String s(test.c_str() + pos, n);
return s;
}
@@ -203,7 +205,8 @@
String assignment(String & test)
{
// 21.3.1
- String s(random(0, 1000), '\0');
+ const typename String::size_type size = random(0, 1000);
+ String s(size, '\0');
typename String::size_type i = 0;
for (; i != s.size(); ++i)
{
@@ -217,7 +220,8 @@
String assignment_with_cstr(String & test)
{
// 21.3.1
- String s(random(0, 1000), '\0');
+ const typename String::size_type size = random(0, 1000);
+ String s(size, '\0');
typename String::size_type i = 0;
for (; i != s.size(); ++i)
{
@@ -310,21 +314,25 @@
template<class String>
String resize(String & test)
{
- test.resize(random(0, test.size()), random('a', 'z'));
+ const typename String::size_type newSize = random(0, test.size());
+ const typename String::value_type value = random('a', 'z');
+ test.resize(newSize, value);
return test;
}
template<class String>
String resize_with_1_argument(String & test)
{
- test.resize(random(0, test.size()));
+ const typename String::size_type newSize = random(0, test.size());
+ test.resize(newSize);
return test;
}
template<class String>
String reserve(String & test)
{
- test.reserve(random(0, 1000));
+ const typename String::size_type reserveSize = random(0, 1000);
+ test.reserve(reserveSize);
return test;
}
@@ -359,8 +367,10 @@
// 21.3.4
if(!test.empty())
{
- test[random(0, test.size() - 1)];
- test.at(random(0, test.size() - 1));
+ const typename String::size_type index1 = random(0, test.size() - 1);
+ test += test[index1];
+ const typename String::size_type index2 = random(0, test.size() - 1);
+ test += test.at(index2);
}
return test;
}
@@ -368,7 +378,8 @@
template<class String>
String operator_plus_equal(String & test)
{
- test += RandomString<String>(MaxString<String>::value);
+ String str(RandomString<String>(MaxString<String>::value));
+ test += str;
return test;
}
@@ -383,7 +394,8 @@
String operator_plus_equal_with_cstr(String & test)
{
// 21.3.5
- test += RandomString<String>(MaxString<String>::value).c_str();
+ String str(RandomString<String>(MaxString<String>::value));
+ test += str.c_str();
return test;
}
@@ -391,7 +403,8 @@
String operator_plus_equal_no_aliasing(String & test)
{
// 21.3.5
- test += String(test.c_str() + random(0, test.size()));
+ const typename String::size_type offset = random(0, test.size());
+ test += String(test.c_str() + offset);
return test;
}
@@ -399,7 +412,8 @@
String operator_plus_equal_aliasing_cstr(String & test)
{
// 21.3.5
- test += test.c_str() + random(0, test.size());
+ const typename String::size_type offset = random(0, test.size());
+ test += test.c_str() + offset;
return test;
}
@@ -415,7 +429,8 @@
String append_string(String & test)
{
// 21.3.5
- test.append(RandomString<String>(MaxString<String>::value));
+ String str(RandomString<String>(MaxString<String>::value));
+ test.append(str);
return test;
}
@@ -424,7 +439,9 @@
{
// 21.3.5
String s(RandomString<String>(MaxString<String>::value));
- test.append(s, random(0, s.size()), random(0, MaxString<String>::value));
+ const typename String::size_type start = random(0, s.size());
+ const typename String::size_type range = random(0, MaxString<String>::value);
+ test.append(s, start, range);
return test;
}
@@ -432,8 +449,9 @@
String append_cstr_size(String & test)
{
// 21.3.5
- String s = RandomString<String>(MaxString<String>::value);
- test.append(s.c_str(), random(0, s.size()));
+ String s(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type size = random(0, s.size());
+ test.append(s.c_str(), size);
return test;
}
@@ -441,15 +459,25 @@
String append_cstr(String & test)
{
// 21.3.5
- test.append(RandomString<String>(MaxString<String>::value).c_str());
+ String str(RandomString<String>(MaxString<String>::value));
+ test.append(str.c_str());
return test;
}
template<class String>
+ String append_count_char(String & test)
+ {
+ // 21.3.5
+ const typename String::size_type count = random(0, MaxString<String>::value);
+ const typename String::value_type value = random('a', 'z');
+ test.append(count, value);
+ return test;
+ }
+
+ template<class String>
String append_iterators(String & test)
{
// 21.3.5
- test.append(random(0, MaxString<String>::value), random('a', 'z'));
std::list<typename String::value_type> lst(RandomList<String>(MaxString<String>::value));
test.append(lst.begin(), lst.end());
return test;
@@ -459,7 +487,8 @@
String push_back_char(String & test)
{
// 21.3.5
- test.push_back(random('a', 'z'));
+ const typename String::value_type value = random('a', 'z');
+ test.push_back(value);
return test;
}
@@ -467,7 +496,8 @@
String assign_string(String & test)
{
// 21.3.5
- test.assign(RandomString<String>(MaxString<String>::value));
+ String str(RandomString<String>(MaxString<String>::value));
+ test.assign(str);
return test;
}
@@ -475,8 +505,10 @@
String assign_string_start_size(String & test)
{
// 21.3.5
- String str = RandomString<String>(MaxString<String>::value);
- test.assign(str, random(0, str.size()), random(0, MaxString<String>::value));
+ String str(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type start = random(0, str.size());
+ const typename String::size_type size = random(0, MaxString<String>::value);
+ test.assign(str, start, size);
return test;
}
@@ -484,8 +516,9 @@
String assign_cstr_size(String & test)
{
// 21.3.5
- String str = RandomString<String>(MaxString<String>::value);
- test.assign(str.c_str(), random(0, str.size()));
+ String str(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type size = random(0, str.size());
+ test.assign(str.c_str(), size);
return test;
}
@@ -493,7 +526,8 @@
String assign_cstr(String & test)
{
// 21.3.5
- test.assign(RandomString<String>(MaxString<String>::value).c_str());
+ String str(RandomString<String>(MaxString<String>::value));
+ test.assign(str.c_str());
return test;
}
@@ -501,7 +535,9 @@
String assign_number_char(String & test)
{
// 21.3.5
- test.assign(random(0, MaxString<String>::value), random('a', 'z'));
+ const typename String::size_type number = random(0, MaxString<String>::value);
+ const typename String::value_type value = random('a', 'z');
+ test.assign(number, value);
return test;
}
@@ -518,7 +554,9 @@
String insert_position_string(String & test)
{
// 21.3.5
- test.insert(random(0, test.size()), RandomString<String>(MaxString<String>::value));
+ const typename String::size_type position = random(0, test.size());
+ String str(RandomString<String>(MaxString<String>::value));
+ test.insert(position, str);
return test;
}
@@ -526,10 +564,11 @@
String insert_position_string_start_end(String & test)
{
// 21.3.5
- String str = RandomString<String>(MaxString<String>::value);
- test.insert(random(0, test.size()),
- str, random(0, str.size()),
- random(0, MaxString<String>::value));
+ String str(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type position = random(0, test.size());
+ const typename String::size_type start = random(0, str.size());
+ const typename String::size_type end = random(0, MaxString<String>::value);
+ test.insert(position, str, start, end);
return test;
}
@@ -537,9 +576,10 @@
String insert_position_cstr_size(String & test)
{
// 21.3.5
- String str = RandomString<String>(MaxString<String>::value);
- test.insert(random(0, test.size()),
- str.c_str(), random(0, str.size()));
+ String str(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type position = random(0, test.size());
+ const typename String::size_type size = random(0, str.size());
+ test.insert(position, str.c_str(), size);
return test;
}
@@ -547,8 +587,9 @@
String insert_position_cstr(String & test)
{
// 21.3.5
- test.insert(random(0, test.size()),
- RandomString<String>(MaxString<String>::value).c_str());
+ const typename String::size_type position = random(0, test.size());
+ String str(RandomString<String>(MaxString<String>::value));
+ test.insert(position, str.c_str());
return test;
}
@@ -556,8 +597,10 @@
String insert_position_number_char(String & test)
{
// 21.3.5
- test.insert(random(0, test.size()),
- random(0, MaxString<String>::value), random('a', 'z'));
+ const typename String::size_type position = random(0, test.size());
+ const typename String::size_type number = random(0, MaxString<String>::value);
+ const typename String::value_type value = random('a', 'z');
+ test.insert(position, number, value);
return test;
}
@@ -565,8 +608,9 @@
String insert_iterator_char(String & test)
{
// 21.3.5
- test.insert(test.begin() + random(0, test.size()),
- random('a', 'z'));
+ const typename String::size_type offset = random(0, test.size());
+ const typename String::value_type value = random('a', 'z');
+ test.insert(test.begin() + offset, value);
return test;
}
@@ -575,8 +619,8 @@
{
// 21.3.5
std::list<typename String::value_type> lst(RandomList<String>(MaxString<String>::value));
- test.insert(test.begin() + random(0, test.size()),
- lst.begin(), lst.end());
+ const typename String::size_type offset = random(0, test.size());
+ test.insert(test.begin() + offset, lst.begin(), lst.end());
return test;
}
@@ -584,7 +628,9 @@
String erase_position_position(String & test)
{
// 21.3.5
- test.erase(random(0, test.size()), random(0, MaxString<String>::value));
+ const typename String::size_type start = random(0, test.size());
+ const typename String::size_type end = random(0, MaxString<String>::value);
+ test.erase(start, end);
return test;
}
@@ -593,7 +639,10 @@
{
// 21.3.5
if(!test.empty())
- test.erase(test.begin() + random(0, test.size()));
+ {
+ const typename String::size_type offset = random(0, test.size());
+ test.erase(test.begin() + offset);
+ }
return test;
}
@@ -601,8 +650,10 @@
String erase_iterator_iterator(String & test)
{
// 21.3.5
- const typename String::iterator i = test.begin() + random(0, test.size());
- test.erase(i, i + random(0, size_t(test.end() - i)));
+ const typename String::size_type offset = random(0, test.size());
+ const typename String::iterator i = test.begin() + offset;
+ const typename String::size_type endOffset = random(0, test.end() - i);
+ test.erase(i, i + endOffset);
return test;
}
@@ -611,7 +662,8 @@
{
// 21.3.5
const typename String::size_type pos = random(0, test.size());
- test.replace(pos, random(0, test.size() - pos), String(test));
+ const typename String::size_type end = random(0, test.size() - pos);
+ test.replace(pos, end, String(test));
return test;
}
@@ -620,7 +672,8 @@
{
// 21.3.5
const typename String::size_type pos = random(0, test.size());
- test.replace(pos, random(0, test.size() - pos), test);
+ const typename String::size_type end = random(0, test.size() - pos);
+ test.replace(pos, end, test);
return test;
}
@@ -629,8 +682,9 @@
{
// 21.3.5
const typename String::size_type pos = random(0, test.size());
- test.replace(pos, pos + random(0, test.size() - pos),
- RandomString<String>(MaxString<String>::value));
+ const typename String::size_type end = random(0, test.size() - pos);
+ String str(RandomString<String>(MaxString<String>::value));
+ test.replace(pos, pos + end, str);
return test;
}
@@ -638,12 +692,11 @@
String replace_start_end_selfcopy_start_end(String & test)
{
// 21.3.5
- const typename String::size_type
- pos1 = random(0, test.size()),
- pos2 = random(0, test.size());
- test.replace(pos1, pos1 + random(0, test.size() - pos1),
- String(test),
- pos2, pos2 + random(0, test.size() - pos2));
+ const typename String::size_type pos1 = random(0, test.size());
+ const typename String::size_type pos2 = random(0, test.size());
+ const typename String::size_type offset1 = random(0, test.size() - pos1);
+ const typename String::size_type offset2 = random(0, test.size() - pos2);
+ test.replace(pos1, pos1 + offset1, String(test), pos2, pos2 + offset2);
return test;
}
@@ -651,11 +704,11 @@
String replace_start_end_self_start_end(String & test)
{
// 21.3.5
- const typename String::size_type
- pos1 = random(0, test.size()),
- pos2 = random(0, test.size());
- test.replace(pos1, pos1 + random(0, test.size() - pos1),
- test, pos2, pos2 + random(0, test.size() - pos2));
+ const typename String::size_type pos1 = random(0, test.size());
+ const typename String::size_type pos2 = random(0, test.size());
+ const typename String::size_type offset1 = random(0, test.size() - pos1);
+ const typename String::size_type offset2 = random(0, test.size() - pos2);
+ test.replace(pos1, pos1 + offset1, test, pos2, pos2 + offset2);
return test;
}
@@ -663,11 +716,12 @@
String replace_start_end_string_start_end(String & test)
{
// 21.3.5
+ String str(RandomString<String>(MaxString<String>::value));
const typename String::size_type pos1 = random(0, test.size());
- String str = RandomString<String>(MaxString<String>::value);
const typename String::size_type pos2 = random(0, str.size());
- test.replace(pos1, pos1 + random(0, test.size() - pos1),
- str, pos2, pos2 + random(0, str.size() - pos2));
+ const typename String::size_type offset1 = random(0, test.size() - pos1);
+ const typename String::size_type offset2 = random(0, str.size() - pos2);
+ test.replace(pos1, pos1 + offset1, str, pos2, pos2 + offset2);
return test;
}
@@ -676,8 +730,8 @@
{
// 21.3.5
const typename String::size_type pos = random(0, test.size());
- test.replace(pos, random(0, test.size() - pos),
- String(test).c_str(), test.size());
+ const typename String::size_type pos2 = random(0, test.size() - pos);
+ test.replace(pos, pos2, String(test).c_str(), test.size());
return test;
}
@@ -686,8 +740,8 @@
{
// 21.3.5
const typename String::size_type pos = random(0, test.size());
- test.replace(pos, random(0, test.size() - pos),
- test.c_str(), test.size());
+ const typename String::size_type pos2 = random(0, test.size() - pos);
+ test.replace(pos, pos2, test.c_str(), test.size());
return test;
}
@@ -695,10 +749,10 @@
String replace_start_end_stringcstr_size(String & test)
{
// 21.3.5
+ String str(RandomString<String>(MaxString<String>::value));
const typename String::size_type pos = random(0, test.size());
- String str = RandomString<String>(MaxString<String>::value);
- test.replace(pos, pos + random(0, test.size() - pos),
- str.c_str(), str.size());
+ const typename String::size_type offset = random(0, test.size() - pos);
+ test.replace(pos, pos + offset, str.c_str(), str.size());
return test;
}
@@ -706,10 +760,10 @@
String replace_start_end_stringcstr(String & test)
{
// 21.3.5
+ String str(RandomString<String>(MaxString<String>::value));
const typename String::size_type pos = random(0, test.size());
- String str = RandomString<String>(MaxString<String>::value);
- test.replace(pos, pos + random(0, test.size() - pos),
- str.c_str());
+ const typename String::size_type offset = random(0, test.size() - pos);
+ test.replace(pos, pos + offset, str.c_str());
return test;
}
@@ -717,9 +771,11 @@
String replace_start_end_number_char(String & test)
{
// 21.3.5
- const typename String::size_type pos = random(0, test.size());
- test.replace(pos, random(0, test.size() - pos),
- random(0, MaxString<String>::value), random('a', 'z'));
+ const typename String::size_type pos1 = random(0, test.size());
+ const typename String::size_type pos2 = random(0, test.size() - pos1);
+ const typename String::size_type number = random(0, MaxString<String>::value);
+ const typename String::value_type value = random('a', 'z');
+ test.replace(pos1, pos2, number, value);
return test;
}
@@ -728,10 +784,8 @@
{
// 21.3.5
const typename String::size_type pos = random(0, test.size());
- test.replace(
- test.begin() + pos,
- test.begin() + pos + random(0, test.size() - pos),
- String(test));
+ const typename String::size_type offset = random(0, test.size() - pos);
+ test.replace(test.begin() + pos, test.begin() + pos + offset, String(test));
return test;
}
@@ -740,10 +794,8 @@
{
// 21.3.5
const typename String::size_type pos = random(0, test.size());
- test.replace(
- test.begin() + pos,
- test.begin() + pos + random(0, test.size() - pos),
- test);
+ const typename String::size_type offset = random(0, test.size() - pos);
+ test.replace(test.begin() + pos, test.begin() + pos + offset, test);
return test;
}
@@ -752,11 +804,9 @@
{
// 21.3.5
const typename String::size_type pos = random(0, test.size());
- test.replace(
- test.begin() + pos,
- test.begin() + pos + random(0, test.size() - pos),
- String(test).c_str(),
- test.size() - random(0, test.size()));
+ const typename String::size_type offset = random(0, test.size() - pos);
+ const typename String::size_type size = random(0, test.size());
+ test.replace(test.begin() + pos, test.begin() + pos + offset, String(test).c_str(), test.size() - size);
return test;
}
@@ -765,11 +815,9 @@
{
// 21.3.5
const typename String::size_type pos = random(0, test.size());
- test.replace(
- test.begin() + pos,
- test.begin() + pos + random(0, test.size() - pos),
- test.c_str(),
- test.size() - random(0, test.size()));
+ const typename String::size_type offset = random(0, test.size() - pos);
+ const typename String::size_type size = random(0, test.size());
+ test.replace(test.begin() + pos, test.begin() + pos + offset, test.c_str(), test.size() - size);
return test;
}
@@ -777,16 +825,12 @@
String replace_iterator_iterator_stringcstr(String & test)
{
// 21.3.5
- const typename String::size_type
- pos = random(0, test.size()),
- n = random(0, test.size() - pos);
+ const typename String::size_type pos = random(0, test.size());
+ const typename String::size_type n = random(0, test.size() - pos);
typename String::iterator b = test.begin();
- const String str = RandomString<String>(MaxString<String>::value);
+ const String str(RandomString<String>(MaxString<String>::value));
const typename String::value_type* s = str.c_str();
- test.replace(
- b + pos,
- b + pos + n,
- s);
+ test.replace(b + pos, b + pos + n, s);
return test;
}
@@ -795,10 +839,10 @@
{
// 21.3.5
const typename String::size_type pos = random(0, test.size());
- test.replace(
- test.begin() + pos,
- test.begin() + pos + random(0, test.size() - pos),
- random(0, MaxString<String>::value), random('a', 'z'));
+ const typename String::size_type pos2 = random(0, test.size() - pos);
+ const typename String::size_type number = random(0, MaxString<String>::value);
+ const typename String::value_type value = random('a', 'z');
+ test.replace(test.begin() + pos, test.begin() + pos + pos2, number, value);
return test;
}
@@ -806,12 +850,9 @@
String copy_pointer_size_position(String & test)
{
// 21.3.5
- std::vector<typename String::value_type>
- vec(random(1, MaxString<String>::value));
- test.copy(
- &vec[0],
- vec.size(),
- random(0, test.size()));
+ std::vector<typename String::value_type> vec(random(1, MaxString<String>::value));
+ const typename String::size_type pos = random(0, test.size());
+ test.copy(&vec[0], vec.size(), pos);
return test;
}
@@ -819,8 +860,9 @@
String member_swap(String & test)
{
// 21.3.5
- RandomString<String>(MaxString<String>::value).swap(test);
- return test;
+ String s(RandomString<String>(MaxString<String>::value));
+ s.swap(test);
+ return test + " -- " + s;
}
template<class String>
@@ -828,17 +870,42 @@
{
// 21.3.5
String s(RandomString<String>(MaxString<String>::value));
- s.swap(test);
- return s;
+ test.swap(s);
+ return test + " -- " + s;
}
template<class String>
+ String member_self_swap(String & test)
+ {
+ // 21.3.5
+ test.swap(test);
+ return test;
+ }
+
+ template<class String>
+ String member_selfcopy_swap(String & test)
+ {
+ // 21.3.5
+ String(test).swap(test);
+ return test;
+ }
+
+ template<class String>
+ String member_selfcopy_swap2(String & test)
+ {
+ // 21.3.5
+ String s(test);
+ test.swap(s);
+ return test + " -- " + s;
+ }
+
+ template<class String>
String swap(String & test)
{
using std::swap;
String s(RandomString<String>(MaxString<String>::value));
swap(test, s);
- return test;
+ return test + " -- " + s;
}
template<class String>
@@ -846,18 +913,44 @@
{
using std::swap;
String s(RandomString<String>(MaxString<String>::value));
+ swap(s, test);
+ return test + " -- " + s;
+ }
+
+ template<class String>
+ String swap_self(String & test)
+ {
+ using std::swap;
+ swap(test, test);
+ return test;
+ }
+
+ template<class String>
+ String swap_selfcopy(String & test)
+ {
+ using std::swap;
+ String s(test);
swap(test, s);
- return s;
+ return test + " -- " + s;
}
template<class String>
+ String swap_selfcopy2(String & test)
+ {
+ using std::swap;
+ String s(test);
+ swap(s, test);
+ return test + " -- " + s;
+ }
+
+ template<class String>
String cstr_data_getallocator(String & test)
{
// 21.3.6
String result;
+ String str(RandomString<String>(MaxString<String>::value));
result += Num2String<String>(test.c_str() == test.data()) + " -- ";
- result += Num2String<String>(test.get_allocator() ==
- RandomString<String>(MaxString<String>::value).get_allocator()) + " -- ";
+ result += Num2String<String>(test.get_allocator() == str.get_allocator()) + " -- ";
return result;
}
@@ -865,10 +958,11 @@
String find_string_index(String & test)
{
// 21.3.6
- String str = test.substr(
- random(0, test.size()),
- random(0, test.size()));
- test = Num2String<String>(test.find(str, random(0, test.size())));
+ const typename String::size_type pos1 = random(0, test.size());
+ const typename String::size_type pos2 = random(0, test.size());
+ String str = test.substr(pos1, pos2);
+ const typename String::size_type index = random(0, test.size());
+ test = Num2String<String>(test.find(str, index));
return test;
}
@@ -876,12 +970,12 @@
String find_stringcstr_index_length(String & test)
{
// 21.3.6
- String str = test.substr(
- random(0, test.size()),
- random(0, test.size()));
- test = Num2String<String>(test.find(str.c_str(),
- random(0, test.size()),
- random(0, str.size())));
+ const typename String::size_type pos1 = random(0, test.size());
+ const typename String::size_type pos2 = random(0, test.size());
+ String str = test.substr(pos1, pos2);
+ const typename String::size_type index = random(0, test.size());
+ const typename String::size_type length = random(0, str.size());
+ test = Num2String<String>(test.find(str.c_str(), index, length));
return test;
}
@@ -889,11 +983,11 @@
String find_stringcstr_index(String & test)
{
// 21.3.6
- String str = test.substr(
- random(0, test.size()),
- random(0, test.size()));
- test = Num2String<String>(test.find(str.c_str(),
- random(0, test.size())));
+ const typename String::size_type pos1 = random(0, test.size());
+ const typename String::size_type pos2 = random(0, test.size());
+ String str = test.substr(pos1, pos2);
+ const typename String::size_type index = random(0, test.size());
+ test = Num2String<String>(test.find(str.c_str(), index));
return test;
}
@@ -901,9 +995,9 @@
String find_char_index(String & test)
{
// 21.3.6
- test = Num2String<String>(test.find(
- random('a', 'z'),
- random(0, test.size())));
+ const typename String::value_type value = random('a', 'z');
+ const typename String::size_type index = random(0, test.size());
+ test = Num2String<String>(test.find(value, index));
return test;
}
@@ -993,10 +1087,11 @@
String rfind_string_index(String & test)
{
// 21.3.6
- String str = test.substr(
- random(0, test.size()),
- random(0, test.size()));
- test = Num2String<String>(test.rfind(str, random(0, test.size())));
+ const typename String::size_type pos1 = random(0, test.size());
+ const typename String::size_type pos2 = random(0, test.size());
+ String str = test.substr(pos1, pos2);
+ const typename String::size_type index = random(0, test.size());
+ test = Num2String<String>(test.rfind(str, index));
return test;
}
@@ -1004,12 +1099,12 @@
String rfind_stringcstr_index_length(String & test)
{
// 21.3.6
- String str = test.substr(
- random(0, test.size()),
- random(0, test.size()));
- test = Num2String<String>(test.rfind(str.c_str(),
- random(0, test.size()),
- random(0, str.size())));
+ const typename String::size_type pos1 = random(0, test.size());
+ const typename String::size_type pos2 = random(0, test.size());
+ String str = test.substr(pos1, pos2);
+ const typename String::size_type index = random(0, test.size());
+ const typename String::size_type length = random(0, str.size());
+ test = Num2String<String>(test.rfind(str.c_str(), index, length));
return test;
}
@@ -1017,11 +1112,11 @@
String rfind_stringcstr_index(String & test)
{
// 21.3.6
- String str = test.substr(
- random(0, test.size()),
- random(0, test.size()));
- test = Num2String<String>(test.rfind(str.c_str(),
- random(0, test.size())));
+ const typename String::size_type pos1 = random(0, test.size());
+ const typename String::size_type pos2 = random(0, test.size());
+ String str = test.substr(pos1, pos2);
+ const typename String::size_type index = random(0, test.size());
+ test = Num2String<String>(test.rfind(str.c_str(), index));
return test;
}
@@ -1029,9 +1124,9 @@
String rfind_char_index(String & test)
{
// 21.3.6
- test = Num2String<String>(test.rfind(
- random('a', 'z'),
- random(0, test.size())));
+ const typename String::value_type value = random('a', 'z');
+ const typename String::size_type index = random(0, test.size());
+ test = Num2String<String>(test.rfind(value, index));
return test;
}
@@ -1039,9 +1134,9 @@
String find_first_of_string_index(String & test)
{
// 21.3.6
- String str = RandomString<String>(MaxString<String>::value);
- test = Num2String<String>(test.find_first_of(str,
- random(0, test.size())));
+ String str(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type index = random(0, test.size());
+ test = Num2String<String>(test.find_first_of(str, index));
return test;
}
@@ -1049,10 +1144,10 @@
String find_first_of_stringcstr_index_length(String & test)
{
// 21.3.6
- String str = RandomString<String>(MaxString<String>::value);
- test = Num2String<String>(test.find_first_of(str.c_str(),
- random(0, test.size()),
- random(0, str.size())));
+ String str(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type index = random(0, test.size());
+ const typename String::size_type length = random(0, str.size());
+ test = Num2String<String>(test.find_first_of(str.c_str(), index, length));
return test;
}
@@ -1060,9 +1155,9 @@
String find_first_of_stringcstr_index(String & test)
{
// 21.3.6
- String str = RandomString<String>(MaxString<String>::value);
- test = Num2String<String>(test.find_first_of(str.c_str(),
- random(0, test.size())));
+ String str(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type index = random(0, test.size());
+ test = Num2String<String>(test.find_first_of(str.c_str(), index));
return test;
}
@@ -1070,9 +1165,9 @@
String find_first_of_char_index(String & test)
{
// 21.3.6
- test = Num2String<String>(test.find_first_of(
- random('a', 'z'),
- random(0, test.size())));
+ const typename String::value_type value = random('a', 'z');
+ const typename String::size_type index = random(0, test.size());
+ test = Num2String<String>(test.find_first_of(value, index));
return test;
}
@@ -1080,9 +1175,9 @@
String find_last_of_string_index(String & test)
{
// 21.3.6
- String str = RandomString<String>(MaxString<String>::value);
- test = Num2String<String>(test.find_last_of(str,
- random(0, test.size())));
+ String str(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type index = random(0, test.size());
+ test = Num2String<String>(test.find_last_of(str, index));
return test;
}
@@ -1090,10 +1185,10 @@
String find_last_of_stringcstr_index_length(String & test)
{
// 21.3.6
- String str = RandomString<String>(MaxString<String>::value);
- test = Num2String<String>(test.find_last_of(str.c_str(),
- random(0, test.size()),
- random(0, str.size())));
+ String str(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type index = random(0, test.size());
+ const typename String::size_type length = random(0, str.size());
+ test = Num2String<String>(test.find_last_of(str.c_str(), index, length));
return test;
}
@@ -1101,9 +1196,9 @@
String find_last_of_stringcstr_index(String & test)
{
// 21.3.6
- String str = RandomString<String>(MaxString<String>::value);
- test = Num2String<String>(test.find_last_of(str.c_str(),
- random(0, test.size())));
+ String str(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type index = random(0, test.size());
+ test = Num2String<String>(test.find_last_of(str.c_str(), index));
return test;
}
@@ -1111,9 +1206,9 @@
String find_last_of_char_index(String & test)
{
// 21.3.6
- test = Num2String<String>(test.find_last_of(
- random('a', 'z'),
- random(0, test.size())));
+ const typename String::value_type value = random('a', 'z');
+ const typename String::size_type index = random(0, test.size());
+ test = Num2String<String>(test.find_last_of(value, index));
return test;
}
@@ -1121,9 +1216,9 @@
String find_first_not_of_string_index(String & test)
{
// 21.3.6
- String str = RandomString<String>(MaxString<String>::value);
- test = Num2String<String>(test.find_first_not_of(str,
- random(0, test.size())));
+ String str(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type index = random(0, test.size());
+ test = Num2String<String>(test.find_first_not_of(str, index));
return test;
}
@@ -1131,10 +1226,10 @@
String find_first_not_of_stringcstr_index_length(String & test)
{
// 21.3.6
- String str = RandomString<String>(MaxString<String>::value);
- test = Num2String<String>(test.find_first_not_of(str.c_str(),
- random(0, test.size()),
- random(0, str.size())));
+ String str(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type index = random(0, test.size());
+ const typename String::size_type length = random(0, str.size());
+ test = Num2String<String>(test.find_first_not_of(str.c_str(), index, length));
return test;
}
@@ -1142,9 +1237,9 @@
String find_first_not_of_stringcstr_index(String & test)
{
// 21.3.6
- String str = RandomString<String>(MaxString<String>::value);
- test = Num2String<String>(test.find_first_not_of(str.c_str(),
- random(0, test.size())));
+ String str(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type index = random(0, test.size());
+ test = Num2String<String>(test.find_first_not_of(str.c_str(), index));
return test;
}
@@ -1152,9 +1247,9 @@
String find_first_not_of_char_index(String & test)
{
// 21.3.6
- test = Num2String<String>(test.find_first_not_of(
- random('a', 'z'),
- random(0, test.size())));
+ const typename String::value_type value = random('a', 'z');
+ const typename String::size_type index = random(0, test.size());
+ test = Num2String<String>(test.find_first_not_of(value, index));
return test;
}
@@ -1162,9 +1257,9 @@
String find_last_not_of_string_index(String & test)
{
// 21.3.6
- String str = RandomString<String>(MaxString<String>::value);
- test = Num2String<String>(test.find_last_not_of(str,
- random(0, test.size())));
+ String str(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type index = random(0, test.size());
+ test = Num2String<String>(test.find_last_not_of(str, index));
return test;
}
@@ -1172,10 +1267,10 @@
String find_last_not_of_stringcstr_index_length(String & test)
{
// 21.3.6
- String str = RandomString<String>(MaxString<String>::value);
- test = Num2String<String>(test.find_last_not_of(str.c_str(),
- random(0, test.size()),
- random(0, str.size())));
+ String str(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type index = random(0, test.size());
+ const typename String::size_type length = random(0, str.size());
+ test = Num2String<String>(test.find_last_not_of(str.c_str(), index, length));
return test;
}
@@ -1183,9 +1278,9 @@
String find_last_not_of_stringcstr_index(String & test)
{
// 21.3.6
- String str = RandomString<String>(MaxString<String>::value);
- test = Num2String<String>(test.find_last_not_of(str.c_str(),
- random(0, test.size())));
+ String str(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type index = random(0, test.size());
+ test = Num2String<String>(test.find_last_not_of(str.c_str(), index));
return test;
}
@@ -1193,9 +1288,9 @@
String find_last_not_of_char_index(String & test)
{
// 21.3.6
- test = Num2String<String>(test.find_last_not_of(
- random('a', 'z'),
- random(0, test.size())));
+ const typename String::value_type value = random('a', 'z');
+ const typename String::size_type index = random(0, test.size());
+ test = Num2String<String>(test.find_last_not_of(value, index));
return test;
}
@@ -1203,7 +1298,9 @@
String substr_index_length(String & test)
{
// 21.3.6
- test = test.substr(random(0, test.size()), random(0, test.size()));
+ const typename String::size_type pos1 = random(0, test.size());
+ const typename String::size_type pos2 = random(0, test.size());
+ test = test.substr(pos1, pos2);
return test;
}
@@ -1220,7 +1317,8 @@
template<class String>
String compare_string(String & test)
{
- int tristate = test.compare(RandomString<String>(MaxString<String>::value));
+ String str(RandomString<String>(MaxString<String>::value));
+ int tristate = test.compare(str);
if (tristate > 0) tristate = 1;
else if (tristate < 0) tristate = 2;
test = Num2String<String>(tristate);
@@ -1230,10 +1328,9 @@
template<class String>
String compare_index_length_selfcopy(String & test)
{
- int tristate = test.compare(
- random(0, test.size()),
- random(0, test.size()),
- String(test));
+ const typename String::size_type index = random(0, test.size());
+ const typename String::size_type length = random(0, test.size());
+ int tristate = test.compare(index, length, String(test));
if (tristate > 0) tristate = 1;
else if (tristate < 0) tristate = 2;
test = Num2String<String>(tristate);
@@ -1243,10 +1340,10 @@
template<class String>
String compare_index_length_string(String & test)
{
- int tristate = test.compare(
- random(0, test.size()),
- random(0, test.size()),
- RandomString<String>(MaxString<String>::value));
+ const typename String::size_type index = random(0, test.size());
+ const typename String::size_type length = random(0, test.size());
+ String str(RandomString<String>(MaxString<String>::value));
+ int tristate = test.compare(index, length, str);
if (tristate > 0) tristate = 1;
else if (tristate < 0) tristate = 2;
test = Num2String<String>(tristate);
@@ -1257,12 +1354,11 @@
String compare_index_length_selfcopy_index_length(String & test)
{
String str = test;
- int tristate = test.compare(
- random(0, test.size()),
- random(0, test.size()),
- str,
- random(0, str.size()),
- random(0, str.size()));
+ const typename String::size_type index = random(0, test.size());
+ const typename String::size_type length = random(0, test.size());
+ const typename String::size_type index2 = random(0, str.size());
+ const typename String::size_type length2 = random(0, str.size());
+ int tristate = test.compare(index, length, str, index2, length2);
if (tristate > 0) tristate = 1;
else if (tristate < 0) tristate = 2;
test = Num2String<String>(tristate);
@@ -1272,13 +1368,12 @@
template<class String>
String compare_index_length_string_index_length(String & test)
{
- String str = RandomString<String>(MaxString<String>::value);
- int tristate = test.compare(
- random(0, test.size()),
- random(0, test.size()),
- str,
- random(0, str.size()),
- random(0, str.size()));
+ String str(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type index = random(0, test.size());
+ const typename String::size_type length = random(0, test.size());
+ const typename String::size_type index2 = random(0, str.size());
+ const typename String::size_type length2 = random(0, str.size());
+ int tristate = test.compare(index, length, str, index2, length2);
if (tristate > 0) tristate = 1;
else if (tristate < 0) tristate = 2;
test = Num2String<String>(tristate);
@@ -1288,8 +1383,8 @@
template<class String>
String compare_stringcstr(String & test)
{
- int tristate = test.compare(
- RandomString<String>(MaxString<String>::value).c_str());
+ String str(RandomString<String>(MaxString<String>::value));
+ int tristate = test.compare(str.c_str());
if (tristate > 0) tristate = 1;
else if (tristate < 0) tristate = 2;
test = Num2String<String>(tristate);
@@ -1299,12 +1394,11 @@
template<class String>
String compare_index_length_stringcstr_length(String & test)
{
- String str = RandomString<String>(MaxString<String>::value);
- int tristate = test.compare(
- random(0, test.size()),
- random(0, test.size()),
- str.c_str(),
- random(0, str.size()));
+ String str(RandomString<String>(MaxString<String>::value));
+ const typename String::size_type index = random(0, test.size());
+ const typename String::size_type length = random(0, test.size());
+ const typename String::size_type index2 = random(0, str.size());
+ int tristate = test.compare(index, length, str.c_str(), index2);
if (tristate > 0) tristate = 1;
else if (tristate < 0) tristate = 2;
test = Num2String<String>(tristate);
@@ -1314,40 +1408,45 @@
template<class String>
String operator_plus(String & test)
{
- test = RandomString<String>(MaxString<String>::value) +
- RandomString<String>(MaxString<String>::value);
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ test = random1 + random2;
return test;
}
template<class String>
String operator_plus_lhs_cstr(String & test)
{
- test = RandomString<String>(MaxString<String>::value).c_str() +
- RandomString<String>(MaxString<String>::value);
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ test = random1.c_str() + random2;
return test;
}
template<class String>
String operator_plus_lhs_char(String & test)
{
- test = typename String::value_type(random('a', 'z')) +
- RandomString<String>(MaxString<String>::value);
+ const typename String::value_type value = random('a', 'z');
+ String random1(RandomString<String>(MaxString<String>::value));
+ test = value + random1;
return test;
}
template<class String>
String operator_plus_rhs_cstr(String & test)
{
- test = RandomString<String>(MaxString<String>::value) +
- RandomString<String>(MaxString<String>::value).c_str();
+ String random1(RandomString<String>(MaxString<String>::value));
+ String random2(RandomString<String>(MaxString<String>::value));
+ test = random1 + random2.c_str();
return test;
}
template<class String>
String operator_plus_rhs_char(String & test)
{
- test = RandomString<String>(MaxString<String>::value) +
- typename String::value_type(random('a', 'z'));
+ const typename String::value_type value = random('a', 'z');
+ String random1(RandomString<String>(MaxString<String>::value));
+ test = random1 + value;
return test;
}
@@ -1396,6 +1495,7 @@
ADD_TEST(append_string_start_range);
ADD_TEST(append_cstr_size);
ADD_TEST(append_cstr);
+ ADD_TEST(append_count_char);
ADD_TEST(append_iterators);
ADD_TEST(push_back_char);
ADD_TEST(assign_string);
@@ -1434,8 +1534,14 @@
ADD_TEST(copy_pointer_size_position);
ADD_TEST(member_swap);
ADD_TEST(member_swap2);
+ ADD_TEST(member_self_swap);
+ ADD_TEST(member_selfcopy_swap);
+ ADD_TEST(member_selfcopy_swap2);
ADD_TEST(swap);
ADD_TEST(swap2);
+ ADD_TEST(swap_self);
+ ADD_TEST(swap_selfcopy);
+ ADD_TEST(swap_selfcopy2);
ADD_TEST(cstr_data_getallocator);
ADD_TEST(find_string_index);
ADD_TEST(find_stringcstr_index_length);
@@ -1612,7 +1718,7 @@
int main()
{
- const time_t initialSeed(time(0));
+ const time_t initialSeed(1236182091 /*time(0)*/);
srand(unsigned(initialSeed));
std::cout << "initial seed = " << initialSeed << "\n\n";
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ric...@us...> - 2009-03-04 07:13:10
|
Revision: 995
http://loki-lib.svn.sourceforge.net/loki-lib/?rev=995&view=rev
Author: rich_sposato
Date: 2009-03-04 07:13:07 +0000 (Wed, 04 Mar 2009)
Log Message:
-----------
Fixed bug 2656893. Removed redundant assertions.
Modified Paths:
--------------
trunk/src/LevelMutex.cpp
Modified: trunk/src/LevelMutex.cpp
===================================================================
--- trunk/src/LevelMutex.cpp 2009-03-03 22:14:49 UTC (rev 994)
+++ trunk/src/LevelMutex.cpp 2009-03-04 07:13:07 UTC (rev 995)
@@ -574,7 +574,6 @@
bool LevelMutexInfo::IsLockedByCurrentThread( void ) const volatile
{
- assert( IsValid() );
LOKI_MUTEX_DEBUG_CODE( Checker checker( this ); (void)checker; )
if ( !IsLocked() )
@@ -593,7 +592,6 @@
bool LevelMutexInfo::IsRecentLock( void ) const volatile
{
- assert( IsValid() );
LOKI_MUTEX_DEBUG_CODE( Checker checker( this ); (void)checker; )
if ( 0 == m_count )
@@ -615,7 +613,6 @@
bool LevelMutexInfo::IsRecentLock( unsigned int count ) const volatile
{
- assert( IsValid() );
LOKI_MUTEX_DEBUG_CODE( Checker checker( this ); (void)checker; )
if ( 0 == count )
@@ -636,7 +633,6 @@
bool LevelMutexInfo::IsLockedByAnotherThread( void ) const volatile
{
- assert( IsValid() );
LOKI_MUTEX_DEBUG_CODE( Checker checker( this ); (void)checker; )
if ( !IsLocked() )
@@ -652,12 +648,11 @@
void LevelMutexInfo::PostLock( void ) volatile
{
- assert( IsValid() );
+ LOKI_MUTEX_DEBUG_CODE( Checker checker( this ); (void)checker; )
assert( 0 == m_count );
assert( nullptr == m_previous );
assert( this != s_currentMutex );
assert( !IsLockedByCurrentThread() );
- LOKI_MUTEX_DEBUG_CODE( Checker checker( this ); (void)checker; )
m_count = 1;
m_previous = s_currentMutex;
@@ -668,12 +663,11 @@
void LevelMutexInfo::PreUnlock( void ) volatile
{
- assert( IsValid() );
+ LOKI_MUTEX_DEBUG_CODE( Checker checker( this ); (void)checker; )
assert( 1 == m_count );
assert( nullptr != s_currentMutex );
assert( this == s_currentMutex );
assert( IsLockedByCurrentThread() );
- LOKI_MUTEX_DEBUG_CODE( Checker checker( this ); (void)checker; )
s_currentMutex = m_previous;
m_previous = nullptr;
@@ -684,7 +678,6 @@
MutexErrors::Type LevelMutexInfo::PreLockCheck( bool forTryLock ) volatile
{
- assert( IsValid() );
LOKI_MUTEX_DEBUG_CODE( Checker checker( this ); (void)checker; )
const unsigned int currentLevel = GetCurrentThreadsLevel();
@@ -719,7 +712,6 @@
MutexErrors::Type LevelMutexInfo::PreUnlockCheck( void ) volatile
{
- assert( IsValid() );
LOKI_MUTEX_DEBUG_CODE( Checker checker( this ); (void)checker; )
if ( 0 == m_count )
@@ -760,9 +752,9 @@
unsigned int level )
{
if ( ( error == MutexErrors::LevelTooHigh )
- && ( error == MutexErrors::LevelTooLow ) )
+ || ( error == MutexErrors::LevelTooLow ) )
{
- throw MutexException( "Error occurred using mutex.", level, error );
+ throw MutexException( "Design error! Program used mutexes in wrong order.", level, error );
}
return error;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <jfb...@us...> - 2009-03-03 22:14:59
|
Revision: 994
http://loki-lib.svn.sourceforge.net/loki-lib/?rev=994&view=rev
Author: jfbastien
Date: 2009-03-03 22:14:49 +0000 (Tue, 03 Mar 2009)
Log Message:
-----------
Refactor some more. Add tests.
Modified Paths:
--------------
trunk/test/flex_string/main.cpp
Modified: trunk/test/flex_string/main.cpp
===================================================================
--- trunk/test/flex_string/main.cpp 2009-03-03 16:29:14 UTC (rev 993)
+++ trunk/test/flex_string/main.cpp 2009-03-03 22:14:49 UTC (rev 994)
@@ -32,14 +32,16 @@
#include <loki/flex/flex_string.h>
-#include <iostream>
#include <cstdio>
#include <cstring>
#include <ctime>
+#include <iostream>
+#include <typeinfo>
+#include <sstream>
+#include <utility>
+#include <vector>
-using namespace std;
-
namespace StringsToTest
{
typedef flex_string<
@@ -100,985 +102,1522 @@
}
-template <class Integral1, class Integral2>
+template<class Integral1, class Integral2>
Integral2 random(Integral1 low, Integral2 up)
{
- Integral2 low2(low);
- assert(up >= low2);
- if (low2 == up) return low;
- Integral2 x = Integral2(low2 + (rand() * (up - low2)) / RAND_MAX);
- assert(x >= low2 && x <= up);
- return x;
+ Integral2 low2(low);
+ assert(up >= low2);
+ if (low2 == up) return low;
+ Integral2 x = Integral2(low2 + (rand() * (up - low2)) / RAND_MAX);
+ assert(x >= low2 && x <= up);
+ return x;
}
-template <class String>
-String RandomString(const String* /* model */, unsigned int maxSize)
+template<class String>
+String RandomString(size_t maxSize)
{
- String result(random(0, maxSize), '\0');
- size_t i = 0;
- for (; i != result.size(); ++i)
- {
- result[i] = random('a', 'z');
- }
- return result;
+ String result(random(0, maxSize), '\0');
+ size_t i = 0;
+ for (; i != result.size(); ++i)
+ {
+ result[i] = random('a', 'z');
+ }
+ return result;
}
-template <class String, class Integral>
-void Num2String(String& str, Integral )
+template<class String, class Integral>
+String Num2String(Integral value)
{
- str.resize(10, '\0');
-// ultoa((unsigned long)n, &str[0], 10);
- sprintf(&str[0], "%ul", 10);
- str.resize(strlen(str.c_str()));
+ typedef typename String::value_type CharType;
+ std::basic_ostringstream<CharType, std::char_traits<CharType>, std::allocator<CharType> > stream;
+ stream << value;
+ return stream.str().c_str();
}
-std::list<char> RandomList(unsigned int maxSize)
+template<class String>
+std::list<typename String::value_type> RandomList(typename String::size_type maxSize)
{
- std::list<char> lst(random(0u, maxSize));
- std::list<char>::iterator i = lst.begin();
- for (; i != lst.end(); ++i)
+ std::list<typename String::value_type> lst(random(0, maxSize));
+ std::list<typename String::value_type>::iterator i = lst.begin();
+ for (; i != lst.end(); ++i)
+ {
+ *i = random('a', 'z');
+ }
+ return lst;
+}
+
+namespace Tests
+{
+ template<class String>
+ struct MaxString
+ {
+ static const typename String::size_type value = 1050;
+ };
+
+
+ template<class String>
+ String default_constructor(String &)
+ {
+ // 21.3.1
+ return String();
+ }
+
+ template<class String>
+ String copy_constructor(String & test)
+ {
+ // 21.3.1
+ String s(test);
+ return s;
+ }
+
+ template<class String>
+ String copy_constructor_with_size_and_range(String & test)
+ {
+ // 21.3.1
+ const typename String::size_type pos = random(0, test.size());
+ String s(test, pos, random(0, test.size() - pos));
+ return s;
+ }
+
+ template<class String>
+ String constructor_with_cstr_and_size(String & test)
+ {
+ // 21.3.1
+ const typename String::size_type
+ pos = random(0, test.size()),
+ n = random(0, test.size() - pos);
+ String s(test.c_str() + pos, n);
+ return s;
+ }
+
+ template<class String>
+ String constructor_with_cstr(String & test)
+ {
+ // 21.3.1
+ const typename String::size_type pos = random(0, test.size());
+ String s(test.c_str() + pos);
+ return s;
+ }
+
+ template<class String>
+ String assignment(String & test)
+ {
+ // 21.3.1
+ String s(random(0, 1000), '\0');
+ typename String::size_type i = 0;
+ for (; i != s.size(); ++i)
{
- *i = random('a', 'z');
+ s[i] = random('a', 'z');
}
- return lst;
-}
+ test = s;
+ return test;
+ }
-int currentTest = 0;
+ template<class String>
+ String assignment_with_cstr(String & test)
+ {
+ // 21.3.1
+ String s(random(0, 1000), '\0');
+ typename String::size_type i = 0;
+ for (; i != s.size(); ++i)
+ {
+ s[i] = random('a', 'z');
+ }
+ test = s.c_str();
+ return test;
+ }
-template <class String>
-String Test(bool avoidAliasing)
-{
- typedef typename String::size_type size_type;
- const size_type maxString = 1000;
+ template<class String>
+ String assignment_aliased(String & test)
+ {
+ // 21.3.1
+ const size_t pos = random(0, test.size());
+ test = test.c_str() + pos;
+ return test;
+ }
- String test;
+ template<class String>
+ String assignment_non_aliased(String & test)
+ {
+ // 21.3.1
+ const size_t pos = random(0, test.size());
+ test = String(test.c_str() + pos);
+ return test;
+ }
- test = RandomString(&test, maxString);
+ template<class String>
+ String assignment_from_char(String & test)
+ {
+ // 21.3.1
+ test = random('a', 'z');
+ return test;
+ }
- static unsigned int functionSelector = 0;
- ++functionSelector;
- currentTest = functionSelector % 95;
- //std::cout << currentTest <<"\n";
- switch (currentTest)
- {
- case 0:
- // test default constructor 21.3.1
- return String();
- break;
- case 1:
- // test copy constructor 21.3.1
- {
- const size_type pos = random(0, test.size());
- String s(test, pos, random(0, static_cast<typename String::size_type>(test.size() - pos)));
- test = s;
- }
- break;
- case 2:
- // test constructor 21.3.1
- {
- const size_type
- pos = random(0, test.size()),
- n = random(0, test.size() - pos);
- String s(test.c_str() + pos, n);
- test = s;
- }
- break;
- case 3:
- // test constructor 21.3.1
- {
- const size_type pos = random(0, test.size());
- String s(test.c_str() + pos);
- test = s;
- }
- break;
- case 4:
- // test assignment 21.3.1
- {
- String s(random(0, 1000), '\0');
- size_type i = 0;
- for (; i != s.size(); ++i)
- {
- s[i] = random('a', 'z');
- }
- test = s;
- }
- break;
- case 5:
- // test assignment 21.3.1
- {
- String s(random(0, 1000), '\0');
- size_type i = 0;
- for (; i != s.size(); ++i)
- {
- s[i] = random('a', 'z');
- }
- test = s.c_str();
- }
- break;
- case 6:
- // test aliased assignment 21.3.1
- {
- const size_t pos = random(0, test.size());
- if (avoidAliasing)
- {
- test = String(test.c_str() + pos);
- }
- else
- {
- test = test.c_str() + pos;
- }
- }
- break;
- case 7:
- // test assignment 21.3.1
- test = random('a', 'z');
- break;
- case 8:
- // exercise iterators 21.3.2
- test.begin();
- test.end();
- test.rbegin();
- test.rend();
- break;
- case 9:
- // exercise capacity 21.3.3
- test.size();
- test.length();
- test.max_size();
- test.capacity();
- break;
- case 10:
- // test resize
- test.resize(random(0, test.size()), random('a', 'z'));
- break;
- case 11:
- // test resize with 1 arg
- test.resize(random(0, test.size()));
- break;
- case 12:
- // test reserve
- test.reserve(random(0, 1000));
- break;
- case 13:
- // test clear
- test.clear(); // skip because std::string doesn't support it
- break;
- case 14:
- // exercise empty
- {
- const char* kEmptyString = "empty";
- const char* kNonEmptyString = "not empty";
- if (test.empty()) test = "empty";
- else test = "not empty";
- // the above assignments don't work yet; use iterator assign
- if (test.empty()) test = String(kEmptyString, kEmptyString + strlen(kEmptyString));
- else test = String(kNonEmptyString, kNonEmptyString + strlen(kNonEmptyString));
- }
- break;
- case 15:
- // exercise element access 21.3.4
- if(!test.empty())
- {
- test[random(0, test.size() - 1)];
- test.at(random(0, test.size() - 1));
- }
- break;
- case 16:
- // 21.3.5 modifiers
- test += RandomString(&test, maxString);
- break;
- case 17:
- // aliasing modifiers
- test += test;
- break;
- case 18:
- // 21.3.5 modifiers
- test += RandomString(&test, maxString).c_str();
- break;
- case 19:
- // aliasing modifiers
- if (avoidAliasing)
- {
- test += String(test.c_str() + random(0, test.size()));
- }
- else
- {
- test += test.c_str() + random(0, test.size());
- }
- break;
- case 20:
- // 21.3.5 modifiers
- test += random('a', 'z');
- break;
- case 21:
- // 21.3.5 modifiers
- test.append(RandomString(&test, maxString));
- break;
- case 22:
- // 21.3.5 modifiers
- {
- String s(RandomString(&test, maxString));
- test.append(s, random(0, s.size()), random(0, maxString));
- }
- break;
- case 23:
- // 21.3.5 modifiers
- {
- String s = RandomString(&test, maxString);
- test.append(s.c_str(), random(0, s.size()));
- }
- break;
- case 24:
- // 21.3.5 modifiers
- test.append(RandomString(&test, maxString).c_str());
- break;
- case 25:
- // 21.3.5 modifiers
- test.append(random(0, maxString), random('a', 'z'));
- break;
- case 26:
- {
- std::list<char> lst(RandomList(maxString));
- test.append(lst.begin(), lst.end());
- }
- break;
- case 27:
- // 21.3.5 modifiers
- // skip push_back, Dinkumware doesn't support it
- test.push_back(random('a', 'z'));
- break;
- case 28:
- // 21.3.5 modifiers
- test.assign(RandomString(&test, maxString));
- break;
- case 29:
- // 21.3.5 modifiers
- {
- String str = RandomString(&test, maxString);
- test.assign(str, random(0, str.size()), random(0, maxString));
- }
- break;
- case 30:
- // 21.3.5 modifiers
- {
- String str = RandomString(&test, maxString);
- test.assign(str.c_str(), random(0, str.size()));
- }
- break;
- case 31:
- // 21.3.5 modifiers
- test.assign(RandomString(&test, maxString).c_str());
- break;
- case 32:
- // 21.3.5 modifiers
- test.assign(random(0, maxString), random('a', 'z'));
- break;
- case 33:
- // 21.3.5 modifiers
- {
- // skip, Dinkumware doesn't support it
- std::list<char> lst(RandomList(maxString));
- test.assign(lst.begin(), lst.end());
- }
- break;
- case 34:
- // 21.3.5 modifiers
- test.insert(random(0, test.size()), RandomString(&test, maxString));
- break;
- case 35:
- // 21.3.5 modifiers
- {
- String str = RandomString(&test, maxString);
- test.insert(random(0, test.size()),
- str, random(0, str.size()),
- random(0, maxString));
- }
- break;
- case 36:
- // 21.3.5 modifiers
- {
- String str = RandomString(&test, maxString);
- test.insert(random(0, test.size()),
- str.c_str(), random(0, str.size()));
- }
- break;
- case 37:
- // 21.3.5 modifiers
- test.insert(random(0, test.size()),
- RandomString(&test, maxString).c_str());
- break;
- case 38:
- // 21.3.5 modifiers
- test.insert(random(0, test.size()),
- random(0, maxString), random('a', 'z'));
- break;
- case 39:
- // 21.3.5 modifiers
- test.insert(test.begin() + random(0, test.size()),
- random('a', 'z'));
- break;
- case 40:
- // 21.3.5 modifiers
- {
- std::list<char> lst(RandomList(maxString));
- test.insert(test.begin() + random(0, test.size()),
- lst.begin(), lst.end());
- }
- break;
- case 41:
- // 21.3.5 modifiers
- test.erase(random(0, test.size()), random(0, maxString));
- break;
- case 42:
- // 21.3.5 modifiers
- if(!test.empty())
- test.erase(test.begin() + random(0, test.size()));
- break;
- case 43:
- // 21.3.5 modifiers
- {
- const typename String::iterator i = test.begin() + random(0, test.size());
- test.erase(i, i + random(0, size_t(test.end() - i)));
- }
- break;
- case 44:
- // 21.3.5 modifiers
- {
- const typename String::size_type pos = random(0, test.size());
- if (avoidAliasing)
- {
- test.replace(pos, random(0, test.size() - pos),
- String(test));
- }
- else
- {
- test.replace(pos, random(0, test.size() - pos), test);
- }
- }
- break;
- case 45:
- // 21.3.5 modifiers
- {
- const typename String::size_type pos = random(0, test.size());
- test.replace(pos, pos + random(0, test.size() - pos),
- RandomString(&test, maxString));
- }
- break;
- case 46:
- // 21.3.5 modifiers
- {
- const size_type
- pos1 = random(0, test.size()),
- pos2 = random(0, test.size());
- if (avoidAliasing)
- {
- test.replace(pos1, pos1 + random(0, test.size() - pos1),
- String(test),
- pos2, pos2 + random(0, test.size() - pos2));
- }
- else
- {
- test.replace(pos1, pos1 + random(0, test.size() - pos1),
- test, pos2, pos2 + random(0, test.size() - pos2));
- }
- }
- break;
- case 47:
- // 21.3.5 modifiers
- {
- const size_type pos1 = random(0, test.size());
- String str = RandomString(&test, maxString);
- const size_type pos2 = random(0, str.size());
- test.replace(pos1, pos1 + random(0, test.size() - pos1),
- str, pos2, pos2 + random(0, str.size() - pos2));
- }
- break;
- case 48:
- // 21.3.5 modifiers
- {
- const size_type pos = random(0, test.size());
- if (avoidAliasing)
- {
- test.replace(pos, random(0, test.size() - pos),
- String(test).c_str(), test.size());
- }
- else
- {
- test.replace(pos, random(0, test.size() - pos),
- test.c_str(), test.size());
- }
- }
- break;
- case 49:
- // 21.3.5 modifiers
- {
- const size_type pos = random(0, test.size());
- String str = RandomString(&test, maxString);
- test.replace(pos, pos + random(0, test.size() - pos),
- str.c_str(), str.size());
- }
- break;
- case 50:
- // 21.3.5 modifiers
- {
- const size_type pos = random(0, test.size());
- String str = RandomString(&test, maxString);
- test.replace(pos, pos + random(0, test.size() - pos),
- str.c_str());
- }
- break;
- case 51:
- // 21.3.5 modifiers
- {
- const size_type pos = random(0, test.size());
- test.replace(pos, random(0, test.size() - pos),
- random(0, maxString), random('a', 'z'));
- }
- break;
- case 52:
- // 21.3.5 modifiers
- {
- const size_type pos = random(0, test.size());
- if (avoidAliasing)
- {
- test.replace(
- test.begin() + pos,
- test.begin() + pos + random(0, test.size() - pos),
- String(test));
- }
- else
- {
- test.replace(
- test.begin() + pos,
- test.begin() + pos + random(0, test.size() - pos),
- test);
- }
- }
- break;
- case 53:
- // 21.3.5 modifiers
- {
- const size_type pos = random(0, test.size());
- if (avoidAliasing)
- {
- test.replace(
- test.begin() + pos,
- test.begin() + pos + random(0, test.size() - pos),
- String(test).c_str(),
- test.size() - random(0, test.size()));
- }
- else
- {
- test.replace(
- test.begin() + pos,
- test.begin() + pos + random(0, test.size() - pos),
- test.c_str(),
- test.size() - random(0, test.size()));
- }
- }
- break;
- case 54:
- // 21.3.5 modifiers
- {
- const size_type
- pos = random(0, test.size()),
- n = random(0, test.size() - pos);
- typename String::iterator b = test.begin();
- const String str = RandomString(&test, maxString);
- const typename String::value_type* s = str.c_str();
- test.replace(
- b + pos,
- b + pos + n,
- s);
- }
- break;
- case 55:
- // 21.3.5 modifiers
- {
- const size_type pos = random(0, test.size());
- test.replace(
- test.begin() + pos,
- test.begin() + pos + random(0, test.size() - pos),
- random(0, maxString), random('a', 'z'));
- }
- break;
- case 56:
- // 21.3.5 modifiers
- {
- std::vector<typename String::value_type>
- vec(random(0, maxString));
- test.copy(
- &vec[0],
- vec.size(),
- random(0, test.size()));
- }
- break;
- case 57:
- // 21.3.5 modifiers
- RandomString(&test, maxString).swap(test);
- break;
- case 58:
- // 21.3.6 string operations
- // exercise c_str() and data()
- assert(test.c_str() == test.data());
- // exercise get_allocator()
- assert(test.get_allocator() ==
- RandomString(&test, maxString).get_allocator());
- break;
- case 59:
- // 21.3.6 string operations
- {
- String str = test.substr(
- random(0, test.size()),
- random(0, test.size()));
- Num2String(test, test.find(str, random(0, test.size())));
- }
- break;
- case 60:
- // 21.3.6 string operations
- {
- String str = test.substr(
- random(0, test.size()),
- random(0, test.size()));
- Num2String(test, test.find(str.c_str(),
- random(0, test.size()),
- random(0, str.size())));
- }
- break;
- case 61:
- // 21.3.6 string operations
- {
- String str = test.substr(
- random(0, test.size()),
- random(0, test.size()));
- Num2String(test, test.find(str.c_str(),
- random(0, test.size())));
- }
- break;
- case 62:
- // 21.3.6 string operations
- Num2String(test, test.find(
- random('a', 'z'),
- random(0, test.size())));
- break;
- case 63:
- // 21.3.6 string operations
- {
- String str = test.substr(
- random(0, test.size()),
- random(0, test.size()));
- Num2String(test, test.rfind(str, random(0, test.size())));
- }
- break;
- case 64:
- // 21.3.6 string operations
- {
- String str = test.substr(
- random(0, test.size()),
- random(0, test.size()));
- Num2String(test, test.rfind(str.c_str(),
- random(0, test.size()),
- random(0, str.size())));
- }
- break;
- case 65:
- // 21.3.6 string operations
- {
- String str = test.substr(
- random(0, test.size()),
- random(0, test.size()));
- Num2String(test, test.rfind(str.c_str(),
- random(0, test.size())));
- }
- break;
- case 66:
- // 21.3.6 string operations
- Num2String(test, test.rfind(
- random('a', 'z'),
- random(0, test.size())));
- break;
- case 67:
- // 21.3.6 string operations
- {
- String str = RandomString(&test, maxString);
- Num2String(test, test.find_first_of(str,
- random(0, test.size())));
- }
- break;
- case 68:
- // 21.3.6 string operations
- {
- String str = RandomString(&test, maxString);
- Num2String(test, test.find_first_of(str.c_str(),
- random(0, test.size()),
- random(0, str.size())));
- }
- break;
- case 69:
- // 21.3.6 string operations
- {
- String str = RandomString(&test, maxString);
- Num2String(test, test.find_first_of(str.c_str(),
- random(0, test.size())));
- }
- break;
- case 70:
- // 21.3.6 string operations
- Num2String(test, test.find_first_of(
- random('a', 'z'),
- random(0, test.size())));
- break;
- case 71:
- // 21.3.6 string operations
- {
- String str = RandomString(&test, maxString);
- Num2String(test, test.find_last_of(str,
- random(0, test.size())));
- }
- break;
- case 72:
- // 21.3.6 string operations
- {
- String str = RandomString(&test, maxString);
- Num2String(test, test.find_last_of(str.c_str(),
- random(0, test.size()),
- random(0, str.size())));
- }
- break;
- case 73:
- // 21.3.6 string operations
- {
- String str = RandomString(&test, maxString);
- Num2String(test, test.find_last_of(str.c_str(),
- random(0, test.size())));
- }
- break;
- case 74:
- // 21.3.6 string operations
- Num2String(test, test.find_last_of(
- random('a', 'z'),
- random(0, test.size())));
- break;
- case 75:
- // 21.3.6 string operations
- {
- String str = RandomString(&test, maxString);
- Num2String(test, test.find_first_not_of(str,
- random(0, test.size())));
- }
- break;
- case 76:
- // 21.3.6 string operations
- {
- String str = RandomString(&test, maxString);
- Num2String(test, test.find_first_not_of(str.c_str(),
- random(0, test.size()),
- random(0, str.size())));
- }
- break;
- case 77:
- // 21.3.6 string operations
- {
- String str = RandomString(&test, maxString);
- Num2String(test, test.find_first_not_of(str.c_str(),
- random(0, test.size())));
- }
- break;
- case 78:
- // 21.3.6 string operations
- Num2String(test, test.find_first_not_of(
- random('a', 'z'),
- random(0, test.size())));
- break;
- case 79:
- // 21.3.6 string operations
- {
- String str = RandomString(&test, maxString);
- Num2String(test, test.find_last_not_of(str,
- random(0, test.size())));
- }
- break;
- case 80:
- // 21.3.6 string operations
- {
- String str = RandomString(&test, maxString);
- Num2String(test, test.find_last_not_of(str.c_str(),
- random(0, test.size()),
- random(0, str.size())));
- }
- break;
- case 81:
- // 21.3.6 string operations
- {
- String str = RandomString(&test, maxString);
- Num2String(test, test.find_last_not_of(str.c_str(),
- random(0, test.size())));
- }
- break;
- case 82:
- // 21.3.6 string operations
- Num2String(test, test.find_last_not_of(
- random('a', 'z'),
- random(0, test.size())));
- break;
- case 83:
- // 21.3.6 string operations
- test = test.substr(random(0, test.size()), random(0, test.size()));
- break;
- case 84:
- {
- int tristate = test.compare(RandomString(&test, maxString));
- if (tristate > 0) tristate = 1;
- else if (tristate < 0) tristate = 2;
- Num2String(test, tristate);
- }
- break;
- case 85:
- {
- int tristate = test.compare(
- random(0, test.size()),
- random(0, test.size()),
- RandomString(&test, maxString));
- if (tristate > 0) tristate = 1;
- else if (tristate < 0) tristate = 2;
- Num2String(test, tristate);
- }
- break;
- case 86:
- {
- String str = RandomString(&test, maxString);
- int tristate = test.compare(
- random(0, test.size()),
- random(0, test.size()),
- str,
- random(0, str.size()),
- random(0, str.size()));
- if (tristate > 0) tristate = 1;
- else if (tristate < 0) tristate = 2;
- Num2String(test, tristate);
- }
- break;
- case 87:
- {
- int tristate = test.compare(
- RandomString(&test, maxString).c_str());
- if (tristate > 0) tristate = 1;
- else if (tristate < 0) tristate = 2;
- Num2String(test, tristate);
- }
- break;
- case 88:
- {
- String str = RandomString(&test, maxString);
- int tristate = test.compare(
- random(0, test.size()),
- random(0, test.size()),
- str.c_str(),
- random(0, str.size()));
- if (tristate > 0) tristate = 1;
- else if (tristate < 0) tristate = 2;
- Num2String(test, tristate);
- }
- break;
- case 89:
- test = RandomString(&test, maxString) +
- RandomString(&test, maxString);
- break;
- case 90:
- test = RandomString(&test, maxString).c_str() +
- RandomString(&test, maxString);
- break;
- case 91:
- test = typename String::value_type(random('a', 'z')) +
- RandomString(&test, maxString);
- break;
- case 92:
- test = RandomString(&test, maxString) +
- RandomString(&test, maxString).c_str();
- break;
- case 93:
- test = RandomString(&test, maxString) +
- RandomString(&test, maxString).c_str();
- break;
- case 94:
- test = RandomString(&test, maxString) +
- typename String::value_type(random('a', 'z'));
- break;
- default:
- assert(((functionSelector + 1) % 96) == 0);
- break;
- }
+ template<class String>
+ String iterators_call(String & test)
+ {
+ // 21.3.2
+ String result;
+ result += Num2String<String>(test.end() - test.begin()) + " -- ";
+ result += Num2String<String>(test.rend() - test.rbegin()) + " -- ";
+ return result;
+ }
+ template<class String>
+ String iterators_equality(String & test)
+ {
+ // 21.3.2
+ String result;
+ result += Num2String<String>(test.size()) + " -- ";
+ if(0 != test.size())
+ {
+ result += Num2String<String>(test.begin() != test.end()) + " -- ";
+ result += Num2String<String>(test.rbegin() != test.rend()) + " -- ";
+ }
+ else
+ {
+ result += Num2String<String>(test.begin() == test.end()) + " -- ";
+ result += Num2String<String>(test.rbegin() == test.rend()) + " -- ";
+ }
+ return result;
+ }
+
+ template<class String>
+ String capacity(String & test)
+ {
+ // 21.3.2
+ String result;
+ result += Num2String<String>(test.size()) + " -- ";
+ result += Num2String<String>(test.length()) + " -- ";
+ test.max_size();
+ test.capacity();
+ result += test;
+ return result;
+ }
+
+ template<class String>
+ String capacity_values(String & test)
+ {
+ // 21.3.2
+ String result;
+ result += Num2String<String>(test.size() == test.length()) + " -- ";
+ result += Num2String<String>(test.capacity() >= test.size()) + " -- ";
+ result += Num2String<String>(test.max_size() >= test.size()) + " -- ";
+ result += Num2String<String>(test.max_size() >= test.capacity()) + " -- ";
+ return result;
+ }
+
+ template<class String>
+ String resize(String & test)
+ {
+ test.resize(random(0, test.size()), random('a', 'z'));
return test;
-}
+ }
-template<class T>
-void checkResults(const std::string& reference, const T& tested)
-{
- if( (tested.size() != reference.size())||
- (std::string(tested.data(), tested.size()) != reference) )
+ template<class String>
+ String resize_with_1_argument(String & test)
+ {
+ test.resize(random(0, test.size()));
+ return test;
+ }
+
+ template<class String>
+ String reserve(String & test)
+ {
+ test.reserve(random(0, 1000));
+ return test;
+ }
+
+ template<class String>
+ String clear(String & test)
+ {
+ test.clear();
+ return test;
+ }
+
+ template<class String>
+ String empty1(String & test)
+ {
+ if (test.empty()) test = "empty";
+ else test = "not empty";
+ return test;
+ }
+
+ template<class String>
+ String empty2(String & test)
+ {
+ const char* kEmptyString = "empty";
+ const char* kNonEmptyString = "not empty";
+ if (test.empty()) test = String(kEmptyString, kEmptyString + strlen(kEmptyString));
+ else test = String(kNonEmptyString, kNonEmptyString + strlen(kNonEmptyString));
+ return test;
+ }
+
+ template<class String>
+ String element_access(String & test)
+ {
+ // 21.3.4
+ if(!test.empty())
{
- std::cout << "\nTest " << currentTest << " failed: \n";
- std::cout << "reference.size() = " << reference.size() << "\n";
- std::cout << "tested.size() = " << tested.size() << "\n";
- std::cout << "reference data = " << reference << "\n";
- std::cout << "tested data = " << tested << "\n";
+ test[random(0, test.size() - 1)];
+ test.at(random(0, test.size() - 1));
}
+ return test;
+ }
- //assert(tested.size() == reference.size());
- //assert(std::string(tested.data(), tested.size()) == reference);
+ template<class String>
+ String operator_plus_equal(String & test)
+ {
+ test += RandomString<String>(MaxString<String>::value);
+ return test;
+ }
+
+ template<class String>
+ String operator_plus_equal_aliasing(String & test)
+ {
+ test += test;
+ return test;
+ }
+
+ template<class String>
+ String operator_plus_equal_with_cstr(String & test)
+ {
+ // 21.3.5
+ test += RandomString<String>(MaxString<String>::value).c_str();
+ return test;
+ }
+
+ template<class String>
+ String operator_plus_equal_no_aliasing(String & test)
+ {
+ // 21.3.5
+ test += String(test.c_str() + random(0, test.size()));
+ return test;
+ }
+
+ template<class String>
+ String operator_plus_equal_aliasing_cstr(String & test)
+ {
+ // 21.3.5
+ test += test.c_str() + random(0, test.size());
+ return test;
+ }
+
+ template<class String>
+ String operator_plus_equal_char(String & test)
+ {
+ // 21.3.5
+ test += random('a', 'z');
+ return test;
+ }
+
+ template<class String>
+ String append_string(String & test)
+ {
+ // 21.3.5
+ test.append(RandomString<String>(MaxString<String>::value));
+ return test;
+ }
+
+ template<class String>
+ String append_string_start_range(String & test)
+ {
+ // 21.3.5
+ String s(RandomString<String>(MaxString<String>::value));
+ test.append(s, random(0, s.size()), random(0, MaxString<String>::value));
+ return test;
+ }
+
+ template<class String>
+ String append_cstr_size(String & test)
+ {
+ // 21.3.5
+ String s = RandomString<String>(MaxString<String>::value);
+ test.append(s.c_str(), random(0, s.size()));
+ return test;
+ }
+
+ template<class String>
+ String append_cstr(String & test)
+ {
+ // 21.3.5
+ test.append(RandomString<String>(MaxString<String>::value).c_str());
+ return test;
+ }
+
+ template<class String>
+ String append_iterators(String & test)
+ {
+ // 21.3.5
+ test.append(random(0, MaxString<String>::value), random('a', 'z'));
+ std::list<typename String::value_type> lst(RandomList<String>(MaxString<String>::value));
+ test.append(lst.begin(), lst.end());
+ return test;
+ }
+
+ template<class String>
+ String push_back_char(String & test)
+ {
+ // 21.3.5
+ test.push_back(random('a', 'z'));
+ return test;
+ }
+
+ template<class String>
+ String assign_string(String & test)
+ {
+ // 21.3.5
+ test.assign(RandomString<String>(MaxString<String>::value));
+ return test;
+ }
+
+ template<class String>
+ String assign_string_start_size(String & test)
+ {
+ // 21.3.5
+ String str = RandomString<String>(MaxString<String>::value);
+ test.assign(str, random(0, str.size()), random(0, MaxString<String>::value));
+ return test;
+ }
+
+ template<class String>
+ String assign_cstr_size(String & test)
+ {
+ // 21.3.5
+ String str = RandomString<String>(MaxString<String>::value);
+ test.assign(str.c_str(), random(0, str.size()));
+ return test;
+ }
+
+ template<class String>
+ String assign_cstr(String & test)
+ {
+ // 21.3.5
+ test.assign(RandomString<String>(MaxString<String>::value).c_str());
+ return test;
+ }
+
+ template<class String>
+ String assign_number_char(String & test)
+ {
+ // 21.3.5
+ test.assign(random(0, MaxString<String>::value), random('a', 'z'));
+ return test;
+ }
+
+ template<class String>
+ String assign_iterators(String & test)
+ {
+ // 21.3.5
+ std::list<typename String::value_type> lst(RandomList<String>(MaxString<String>::value));
+ test.assign(lst.begin(), lst.end());
+ return test;
+ }
+
+ template<class String>
+ String insert_position_string(String & test)
+ {
+ // 21.3.5
+ test.insert(random(0, test.size()), RandomString<String>(MaxString<String>::value));
+ return test;
+ }
+
+ template<class String>
+ String insert_position_string_start_end(String & test)
+ {
+ // 21.3.5
+ String str = RandomString<String>(MaxString<String>::value);
+ test.insert(random(0, test.size()),
+ str, random(0, str.size()),
+ random(0, MaxString<String>::value));
+ return test;
+ }
+
+ template<class String>
+ String insert_position_cstr_size(String & test)
+ {
+ // 21.3.5
+ String str = RandomString<String>(MaxString<String>::value);
+ test.insert(random(0, test.size()),
+ str.c_str(), random(0, str.size()));
+ return test;
+ }
+
+ template<class String>
+ String insert_position_cstr(String & test)
+ {
+ // 21.3.5
+ test.insert(random(0, test.size()),
+ RandomString<String>(MaxString<String>::value).c_str());
+ return test;
+ }
+
+ template<class String>
+ String insert_position_number_char(String & test)
+ {
+ // 21.3.5
+ test.insert(random(0, test.size()),
+ random(0, MaxString<String>::value), random('a', 'z'));
+ return test;
+ }
+
+ template<class String>
+ String insert_iterator_char(String & test)
+ {
+ // 21.3.5
+ test.insert(test.begin() + random(0, test.size()),
+ random('a', 'z'));
+ return test;
+ }
+
+ template<class String>
+ String insert_iterator_iterator_range(String & test)
+ {
+ // 21.3.5
+ std::list<typename String::value_type> lst(RandomList<String>(MaxString<String>::value));
+ test.insert(test.begin() + random(0, test.size()),
+ lst.begin(), lst.end());
+ return test;
+ }
+
+ template<class String>
+ String erase_position_position(String & test)
+ {
+ // 21.3.5
+ test.erase(random(0, test.size()), random(0, MaxString<String>::value));
+ return test;
+ }
+
+ template<class String>
+ String erase_iterator(String & test)
+ {
+ // 21.3.5
+ if(!test.empty())
+ test.erase(test.begin() + random(0, test.size()));
+ return test;
+ }
+
+ template<class String>
+ String erase_iterator_iterator(String & test)
+ {
+ // 21.3.5
+ const typename String::iterator i = test.begin() + random(0, test.size());
+ test.erase(i, i + random(0, size_t(test.end() - i)));
+ return test;
+ }
+
+ template<class String>
+ String replace_start_end_copyself(String & test)
+ {
+ // 21.3.5
+ const typename String::size_type pos = random(0, test.size());
+ test.replace(pos, random(0, test.size() - pos), String(test));
+ return test;
+ }
+
+ template<class String>
+ String replace_start_end_self(String & test)
+ {
+ // 21.3.5
+ const typename String::size_type pos = random(0, test.size());
+ test.replace(pos, random(0, test.size() - pos), test);
+ return test;
+ }
+
+ template<class String>
+ String replace_start_end_string(String & test)
+ {
+ // 21.3.5
+ const typename String::size_type pos = random(0, test.size());
+ test.replace(pos, pos + random(0, test.size() - pos),
+ RandomString<String>(MaxString<String>::value));
+ return test;
+ }
+
+ template<class String>
+ String replace_start_end_selfcopy_start_end(String & test)
+ {
+ // 21.3.5
+ const typename String::size_type
+ pos1 = random(0, test.size()),
+ pos2 = random(0, test.size());
+ test.replace(pos1, pos1 + random(0, test.size() - pos1),
+ String(test),
+ pos2, pos2 + random(0, test.size() - pos2));
+ return test;
+ }
+
+ template<class String>
+ String replace_start_end_self_start_end(String & test)
+ {
+ // 21.3.5
+ const typename String::size_type
+ pos1 = random(0, test.size()),
+ pos2 = random(0, test.size());
+ test.replace(pos1, pos1 + random(0, test.size() - pos1),
+ test, pos2, pos2 + random(0, test.size() - pos2));
+ return test;
+ }
+
+ template<class String>
+ String replace_start_end_string_start_end(String & test)
+ {
+ // 21.3.5
+ const typename String::size_type pos1 = random(0, test.size());
+ String str = RandomString<String>(MaxString<String>::value);
+ const typename String::size_type pos2 = random(0, str.size());
+ test.replace(pos1, pos1 + random(0, test.size() - pos1),
+ str, pos2, pos2 + random(0, str.size() - pos2));
+ return test;
+ }
+
+ template<class String>
+ String replace_start_end_selfcopycstr_size(String & test)
+ {
+ // 21.3.5
+ const typename String::size_type pos = random(0, test.size());
+ test.replace(pos, random(0, test.size() - pos),
+ String(test).c_str(), test.size());
+ return test;
+ }
+
+ template<class String>
+ String replace_start_end_selfcstr_size(String & test)
+ {
+ // 21.3.5
+ const typename String::size_type pos = random(0, test.size());
+ test.replace(pos, random(0, test.size() - pos),
+ test.c_str(), test.size());
+ return test;
+ }
+
+ template<class String>
+ String replace_start_end_stringcstr_size(String & test)
+ {
+ // 21.3.5
+ const typename String::size_type pos = random(0, test.size());
+ String str = RandomString<String>(MaxString<String>::value);
+ test.replace(pos, pos + random(0, test.size() - pos),
+ str.c_str(), str.size());
+ return test;
+ }
+
+ template<class String>
+ String replace_start_end_stringcstr(String & test)
+ {
+ // 21.3.5
+ const typename String::size_type pos = random(0, test.size());
+ String str = RandomString<String>(MaxString<String>::value);
+ test.replace(pos, pos + random(0, test.size() - pos),
+ str.c_str());
+ return test;
+ }
+
+ template<class String>
+ String replace_start_end_number_char(String & test)
+ {
+ // 21.3.5
+ const typename String::size_type pos = random(0, test.size());
+ test.replace(pos, random(0, test.size() - pos),
+ random(0, MaxString<String>::value), random('a', 'z'));
+ return test;
+ }
+
+ template<class String>
+ String replace_iterator_iterator_selfcopy(String & test)
+ {
+ // 21.3.5
+ const typename String::size_type pos = random(0, test.size());
+ test.replace(
+ test.begin() + pos,
+ test.begin() + pos + random(0, test.size() - pos),
+ String(test));
+ return test;
+ }
+
+ template<class String>
+ String replace_iterator_iterator_self(String & test)
+ {
+ // 21.3.5
+ const typename String::size_type pos = random(0, test.size());
+ test.replace(
+ test.begin() + pos,
+ test.begin() + pos + random(0, test.size() - pos),
+ test);
+ return test;
+ }
+
+ template<class String>
+ String replace_iterator_iterator_selfcopycstr_size(String & test)
+ {
+ // 21.3.5
+ const typename String::size_type pos = random(0, test.size());
+ test.replace(
+ test.begin() + pos,
+ test.begin() + pos + random(0, test.size() - pos),
+ String(test).c_str(),
+ test.size() - random(0, test.size()));
+ return test;
+ }
+
+ template<class String>
+ String replace_iterator_iterator_selfcstr_size(String & test)
+ {
+ // 21.3.5
+ const typename String::size_type pos = random(0, test.size());
+ test.replace(
+ test.begin() + pos,
+ test.begin() + pos + random(0, test.size() - pos),
+ test.c_str(),
+ test.size() - random(0, test.size()));
+ return test;
+ }
+
+ template<class String>
+ String replace_iterator_iterator_stringcstr(String & test)
+ {
+ // 21.3.5
+ const typename String::size_type
+ pos = random(0, test.size()),
+ n = random(0, test.size() - pos);
+ typename String::iterator b = test.begin();
+ const String str = RandomString<String>(MaxString<String>::value);
+ const typename String::value_type* s = str.c_str();
+ test.replace(
+ b + pos,
+ b + pos + n,
+ s);
+ return test;
+ }
+
+ template<class String>
+ String replace_iterator_iterator_number_char(String & test)
+ {
+ // 21.3.5
+ const typename String::size_type pos = random(0, test.size());
+ test.replace(
+ test.begin() + pos,
+ test.begin() + pos + random(0, test.size() - pos),
+ random(0, MaxString<String>::value), random('a', 'z'));
+ return test;
+ }
+
+ template<class String>
+ String copy_pointer_size_position(String & test)
+ {
+ // 21.3.5
+ std::vector<typename String::value_type>
+ vec(random(1, MaxString<String>::value));
+ test.copy(
+ &vec[0],
+ vec.size(),
+ random(0, test.size()));
+ return test;
+ }
+
+ template<class String>
+ String member_swap(String & test)
+ {
+ // 21.3.5
+ RandomString<String>(MaxString<String>::value).swap(test);
+ return test;
+ }
+
+ template<class String>
+ String member_swap2(String & test)
+ {
+ // 21.3.5
+ String s(RandomString<String>(MaxString<String>::value));
+ s.swap(test);
+ return s;
+ }
+
+ template<class String>
+ String swap(String & test)
+ {
+ using std::swap;
+ String s(RandomString<String>(MaxString<String>::value));
+ swap(test, s);
+ return test;
+ }
+
+ template<class String>
+ String swap2(String & test)
+ {
+ using std::swap;
+ String s(RandomString<String>(MaxString<String>::value));
+ swap(test, s);
+ return s;
+ }
+
+ template<class String>
+ String cstr_data_getallocator(String & test)
+ {
+ // 21.3.6
+ String result;
+ result += Num2String<String>(test.c_str() == test.data()) + " -- ";
+ result += Num2String<String>(test.get_allocator() ==
+ RandomString<String>(MaxString<String>::value).get_allocator()) + " -- ";
+ return result;
+ }
+
+ template<class String>
+ String find_string_index(String & test)
+ {
+ // 21.3.6
+ String str = test.substr(
+ random(0, test.size()),
+ random(0, test.size()));
+ test = Num2String<String>(test.find(str, random(0, test.size())));
+ return test;
+ }
+
+ template<class String>
+ String find_stringcstr_index_length(String & test)
+ {
+ // 21.3.6
+ String str = test.substr(
+ random(0, test.size()),
+ random(0, test.size()));
+ test = Num2String<String>(test.find(str.c_str(),
+ random(0, test.size()),
+ random(0, str.size())));
+ return test;
+ }
+
+ template<class String>
+ String find_stringcstr_index(String & test)
+ {
+ // 21.3.6
+ String str = test.substr(
+ random(0, test.size()),
+ random(0, test.size()));
+ test = Num2String<String>(test.find(str.c_str(),
+ random(0, test.size())));
+ return test;
+ }
+
+ template<class String>
+ String find_char_index(String & test)
+ {
+ // 21.3.6
+ test = Num2String<String>(test.find(
+ random('a', 'z'),
+ random(0, test.size())));
+ return test;
+ }
+
+ template<class String>
+ String find_overflow(String & test)
+ {
+ // This tests bug 2536490.
+
+ test = String();
+
+ String result;
+
+ // Validate that find with a single character doesn't overflow.
+ result += Num2String<String>(test.find('6'));
+ result += " -- ";
+ test = "12345";
+ result += Num2String<String>(test.find('6'));
+ result += " -- ";
+ test = "123456";
+ result += Num2String<String>(test.find('6'));
+ result += " -- ";
+ test = "12345";
+ result += Num2String<String>(test.find('6'));
+ result += " -- ";
+
+ // Validate that find with multiple characters doesn't overflow.
+ test = "12345";
+ result += Num2String<String>(test.find("123"));
+ result += " -- ";
+ test = "12345";
+ result += Num2String<String>(test.find("12345"));
+ result += " -- ";
+ test = "12345";
+ result += Num2String<String>(test.find("345"));
+ result += " -- ";
+ test = "123456";
+ result += Num2String<String>(test.find("456"));
+ result += " -- ";
+ test = "12345";
+ result += Num2String<String>(test.find("456"));
+ result += " -- ";
+
+ return result;
+ }
+
+ template<class String>
+ String rfind_overflow(String & test)
+ {
+ test = String();
+
+ String result;
+
+ // Validate that rfind with a single character doesn't overflow.
+ result += Num2String<String>(test.rfind('6'));
+ result += " -- ";
+ test = "12345";
+ result += Num2String<String>(test.rfind('6'));
+ result += " -- ";
+ test = "123456";
+ result += Num2String<String>(test.rfind('6'));
+ result += " -- ";
+ test = "12345";
+ result += Num2String<String>(test.rfind('6'));
+ result += " -- ";
+
+ // Validate that rfind with multiple characters doesn't overflow.
+ test = "12345";
+ result += Num2String<String>(test.rfind("123"));
+ result += " -- ";
+ test = "12345";
+ result += Num2String<String>(test.rfind("12345"));
+ result += " -- ";
+ test = "12345";
+ result += Num2String<String>(test.rfind("345"));
+ result += " -- ";
+ test = "123456";
+ result += Num2String<String>(test.rfind("456"));
+ result += " -- ";
+ test = "12345";
+ result += Num2String<String>(test.rfind("456"));
+ result += " -- ";
+
+ return result;
+ }
+
+ template<class String>
+ String rfind_string_index(String & test)
+ {
+ // 21.3.6
+ String str = test.substr(
+ random(0, test.size()),
+ random(0, test.size()));
+ test = Num2String<String>(test.rfind(str, random(0, test.size())));
+ return test;
+ }
+
+ template<class String>
+ String rfind_stringcstr_index_length(String & test)
+ {
+ // 21.3.6
+ String str = test.substr(
+ random(0, test.size()),
+ random(0, test.size()));
+ test = Num2String<String>(test.rfind(str.c_str(),
+ random(0, test.size()),
+ random(0, str.size())));
+ return test;
+ }
+
+ template<class String>
+ String rfind_stringcstr_index(String & test)
+ {
+ // 21.3.6
+ String str = test.substr(
+ random(0, test.size()),
+ random(0, test.size()));
+ test = Num2String<String>(test.rfind(str.c_str(),
+ random(0, test.size())));
+ return test;
+ }
+
+ template<class String>
+ String rfind_char_index(String & test)
+ {
+ // 21.3.6
+ test = Num2String<String>(test.rfind(
+ random('a', 'z'),
+ random(0, test.size())));
+ return test;
+ }
+
+ template<class String>
+ String find_first_of_string_index(String & test)
+ {
+ // 21.3.6
+ String str = RandomString<String>(MaxString<String>::value);
+ test = Num2String<String>(test.find_first_of(str,
+ random(0, test.size())));
+ return test;
+ }
+
+ template<class String>
+ String find_first_of_stringcstr_index_length(String & test)
+ {
+ // 21.3.6
+ String str = RandomString<String>(MaxString<String>::value);
+ test = Num2String<String>(test.find_first_of(str.c_str(),
+ random(0, test.size()),
+ random(0, str.size())));
+ return test;
+ }
+
+ template<class String>
+ String find_first_of_stringcstr_index(String & test)
+ {
+ // 21.3.6
+ String str = RandomString<String>(MaxString<String>::value);
+ test = Num2String<String>(test.find_first_of(str.c_str(),
+ random(0, test.size())));
+ return test;
+ }
+
+ template<class String>
+ String find_first_of_char_index(String & test)
+ {
+ // 21.3.6
+ test = Num2String<String>(test.find_first_of(
+ random('a', 'z'),
+ random(0, test.size())));
+ return test;
+ }
+
+ template<class String>
+ String find_last_of_string_index(String & test)
+ {
+ // 21.3.6
+ String str = RandomString<String>(MaxString<String>::value);
+ test = Num2String<String>(test.find_last_of(str,
+ random(0, test.size())));
+ return test;
+ }
+
+ template<class String>
+ String find_last_of_stringcstr_index_length(String & test)
+ {
+ // 21.3.6
+ String str = RandomString<String>(MaxString<String>::value);
+ test = Num2String<String>(test.find_last_of(str.c_str(),
+ random(0, test.size()),
+ random(0, str.size())));
+ return test;
+ }
+
+ template<class String>
+ String find_last_of_stringcstr_index(String & test)
+ {
+ // 21.3.6
+ String str = RandomString<String>(MaxString<String>::value);
+ test = Num2String<String>(test.find_last_of(str.c_str(),
+ random(0, test.size())));
+ return test;
+ }
+
+ template<class String>
+ String find_last_of_char_index(String & test)
+ {
+ // 21.3.6
+ test = Num2String<String>(test.find_last_of(
+ random('a', 'z'),
+ random(0, test.size())));
+ return test;
+ }
+
+ template<class String>
+ String find_first_not_of_string_index(String & test)
+ {
+ // 21.3.6
+ String str = RandomString<String>(MaxString<String>::value);
+ test = Num2String<String>(test.find_first_not_of(str,
+ random(0, test.size())));
+ return test;
+ }
+
+ template<class String>
+ String find_first_not_of_stringcstr_index_length(String & test)
+ {
+ // 21.3.6
+ String str = RandomString<String>(MaxString<String>::value);
+ test = Num2String<String>(test.find_first_not_of(str.c_str(),
+ random(0, test.size()),
+ random(0, str.size())));
+ return test;
+ }
+
+ template<class String>
+ String find_first_not_of_stringcstr_index(String & test)
+ {
+ // 21.3.6
+ String str = RandomString<String>(MaxString<String>::value);
+ test = Num2String<String>(test.find_first_not_of(str.c_str(),
+ random(0, test.size())));
+ return test;
+ }
+
+ template<class String>
+ String find_first_not_of_char_index(String & test)
+ {
+ // 21.3.6
+ test = Num2String<String>(test.find_first_not_of(
+ random('a', 'z'),
+ random(0, test.size())));
+ return test;
+ }
+
+ template<class String>
+ String find_last_not_of_string_index(String & test)
+ {
+ // 21.3.6
+ String str = RandomString<String>(MaxString<String>::value);
+ test = Num2String<String>(test.find_last_not_of(str,
+ random(0, test.size())));
+ return test;
+ }
+
+ template<class String>
+ String find_last_not_of_stringcstr_index_length(String & test)
+ {
+ // 21.3.6
+ String str = RandomString<String>(MaxString<String>::value);
+ test = Num2String<String>(test.find_last_not_of(str.c_str(),
+ random(0, test.size()),
+ random(0, str.size())));
+ return test;
+ }
+
+ template<class String>
+ String find_last_not_of_stringcstr_index(String & test)
+ {
+ // 21.3.6
+ String str = RandomString<String>(MaxString<String>::value);
+ test = Num2String<String>(test.find_last_not_of(str.c_str(),
+ random(0, test.size())));
+ return test;
+ }
+
+ template<class String>
+ String find_last_not_of_char_index(String & test)
+ {
+ // 21.3.6
+ test = Num2String<String>(test.find_last_not_of(
+ random('a', 'z'),
+ random(0, test.size())));
+ return test;
+ }
+
+ template<class String>
+ String substr_index_length(String & test)
+ {
+ // 21.3.6
+ test = test.substr(random(0, test.size()), random(0, test.size()));
+ return test;
+ }
+
+ template<class String>
+ String compare_selfcopy(String & test)
+ {
+ int tristate = test.compare(String(test));
+ if (tristate > 0) tristate = 1;
+ else if (tristate < 0) tristate = 2;
+ test = Num2String<String>(tristate);
+ return test;
+ }
+
+ template<class String>
+ String compare_string(String & test)
+ {
+ int tristate = test.compare(RandomString<String>(MaxString<String>::value));
+ if (tristate > 0) tristate = 1;
+ else if (tristate < 0) tristate = 2;
+ test = Num2String<String>(tristate);
+ return test;
+ }
+
+ template<class String>
+ String compare_index_length_selfcopy(String & test)
+ {
+ int tristate = test.compare(
+ random(0, test.size()),
+ random(0, test.size()),
+ String(test));
+ if (tristate > 0) tristate = 1;
+ else if (tristate < 0) tristate = 2;
+ test = Num2String<String>(tristate);
+ return test;
+ }
+
+ template<class String>
+ String compare_index_length_string(String & test)
+ {
+ int tristate = test.compare(
+ random(0, test.size()),
+ random(0, test.size()),
+ RandomString<String>(MaxString<String>::value));
+ if (tristate > 0) tristate = 1;
+ else if (tristate < 0) tristate = 2;
+ test = Num2String<String>(tristate);
+ return test;
+ }
+
+ template<class String>
+ String compare_index_length_selfcopy_index_length(String & test)
+ {
+ String str = test;
+ int tristate = test.compare(
+ random(0, test.size()),
+ random(0, test.size()),
+ str,
+ random(0, str.size()),
+ random(0, str.size()));
+ if (tristate > 0) tristate = 1;
+ else if (tristate < 0) tristate = 2;
+ test = Num2String<String>(tristate);
+ return test;
+ }
+
+ template<class String>
+ String compare_index_length_string_index_length(String & test)
+ {
+ String str = RandomString<String>(MaxString<String>::value);
+ int tristate = test.compare(
+ random(0, test.size()),
+ random(0, test.size()),
+ str,
+ random(0, str.size()),
+ random(0, str.size()));
+ if (tristate > 0) tristate = 1;
+ else if (tristate < 0) tristate = 2;
+ test = Num2String<String>(tristate);
+ return test;
+ }
+
+ template<class String>
+ String compare_stringcstr(String & test)
+ {
+ int tristate = test.compare(
+ RandomString<String>(MaxString<String>::value).c_str());
+ if (tristate > 0) tristate = 1;
+ else if (tristate < 0) tristate = 2;
+ test = Num2String<String>(tristate);
+ return test;
+ }
+
+ template<class String>
+ String compare_index_length_stringcstr_length(String & test)
+ {
+ String str = RandomString<String>(MaxString<String>::value);
+ int tristate = test.compare(
+ random(0, test.size()),
+ random(0, test.size()),
+ str.c_str(),
+ random(0, str.size()));
+ if (tristate > 0) tristate = 1;
+ else if (tristate < 0) tristate = 2;
+ test = Num2String<String>(tristate);
+ return test;
+ }
+
+ template<class String>
+ String operator_plus(String & test)
+ {
+ test = RandomString<String>(MaxString<String>::value) +
+ RandomString<String>(MaxString<String>::value);
+ return test;
+ }
+
+ template<class String>
+ String operator_plus_lhs_cstr(String & test)
+ {
+ test = RandomString<String>(MaxString<String>::value).c_str() +
+ RandomString<String>(MaxString<String>::value);
+ return test;
+ }
+
+ template<class String>
+ String operator_plus_lhs_char(String & test)
+ {
+ test = typename String::value_type(random('a', 'z')) +
+ RandomString<String>(MaxString<String>::value);
+ return test;
+ }
+
+ template<class String>
+ String operator_plus_rhs_cstr(String & test)
+ {
+ test = RandomString<String>(MaxString<String>::value) +
+ RandomString<String>(MaxString<String>::value).c_str();
+ return test;
+ }
+
+ template<class String>
+ String operator_plus_rhs_char(String & test)
+ {
+ test = RandomString<String>(MaxString<String>::value) +
+ typename String::value_type(random('a', 'z'));
+ return test;
+ }
+
}
-void Compare()
+
+template<class String>
+class TestFunctions
{
- unsigned int count = 0;
- srand(10);
- for (;;)
- {
- cout << ++count << '\r';
+public:
+ typedef String (*TestFunction)(String &);
- unsigned long t = rand(); //time(0);
+ T...
[truncated message content] |
|
From: <jfb...@us...> - 2009-03-03 16:29:15
|
Revision: 993
http://loki-lib.svn.sourceforge.net/loki-lib/?rev=993&view=rev
Author: jfbastien
Date: 2009-03-03 16:29:14 +0000 (Tue, 03 Mar 2009)
Log Message:
-----------
Bug 2657248: take two, this time fix it properly!
Modified Paths:
--------------
trunk/include/loki/flex/flex_string_shell.h
Modified: trunk/include/loki/flex/flex_string_shell.h
===================================================================
--- trunk/include/loki/flex/flex_string_shell.h 2009-03-03 13:32:21 UTC (rev 992)
+++ trunk/include/loki/flex/flex_string_shell.h 2009-03-03 16:29:14 UTC (rev 993)
@@ -807,25 +807,24 @@
const typename std::iterator_traits<FwdIterator>::difference_type n2 =
std::distance(s1, s2);
+ assert(n2 >= 0);
- // Empty replacement.
- if(0 == n2)
- return;
-
- assert(n2 > 0);
-
- // Handle aliased replace
- static const std::less_equal<const value_type*> le =
- std::less_equal<const value_type*>();
- const bool aliased = le(&*begin(), &*s1) && le(&*s1, &*end());
- if (aliased /* && capacity() < size() - n1 + n2 */)
+ // Make sure the replacement isn't empty.
+ if(0 != n2)
{
- // Aliased replace, copy to new string
- flex_string temp;
- temp.reserve(size() - n1 + n2);
- temp.append(begin(), i1).append(s1, s2).append(i2, end());
- swap(temp);
- return;
+ // Handle aliased replace
+ static const std::less_equal<const value_type*> le =
+ std::less_equal<const value_type*>();
+ const bool aliased = le(&*begin(), &*s1) && le(&*s1, &*end());
+ if (aliased /* && capacity() < size() - n1 + n2 */)
+ {
+ // Aliased replace, copy to new string
+ flex_string temp;
+ temp.reserve(size() - n1 + n2);
+ temp.append(begin(), i1).append(s1, s2).append(i2, end());
+ swap(temp);
+ return;
+ }
}
if (n1 > n2)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|