mirror of
https://github.com/boostorg/algorithm.git
synced 2025-06-26 20:41:42 +02:00
Compare commits
32 Commits
boost-1.38
...
svn-branch
Author | SHA1 | Date | |
---|---|---|---|
300bb14514 | |||
7299b29bf8 | |||
539c170b9d | |||
c81ee948b7 | |||
ba5e4c30c6 | |||
cd26ed816c | |||
4e15767bed | |||
9fa2f90db4 | |||
35f317aeac | |||
d0a03fdb4e | |||
346f032be2 | |||
a389d768c4 | |||
90fca39906 | |||
5b24f31486 | |||
b25d6511b3 | |||
1541a554f5 | |||
7a97b3390e | |||
6e5a7497ae | |||
f0b8b60379 | |||
66019abb2f | |||
8758222006 | |||
4eef56761a | |||
b94a3fbfba | |||
614cc2ebab | |||
869660ed14 | |||
777f30780e | |||
26aa37733b | |||
f1e60579c2 | |||
389dd3c863 | |||
f23f61ae9b | |||
608112b112 | |||
b21b54dc4e |
@ -1,20 +0,0 @@
|
|||||||
#----------------------------------------------------------------------------
|
|
||||||
# This file was automatically generated from the original CMakeLists.txt file
|
|
||||||
# Add a variable to hold the headers for the library
|
|
||||||
set (lib_headers
|
|
||||||
algorithm
|
|
||||||
)
|
|
||||||
|
|
||||||
# Add a library target to the build system
|
|
||||||
boost_library_project(
|
|
||||||
algorithm
|
|
||||||
# SRCDIRS
|
|
||||||
TESTDIRS minmax/test string/test
|
|
||||||
HEADERS ${lib_headers}
|
|
||||||
# DOCDIRS
|
|
||||||
DESCRIPTION "A library of various algorithms."
|
|
||||||
MODULARIZED
|
|
||||||
AUTHORS "Pavol Droba <droba -at- topmail.sk>"
|
|
||||||
"Herve Bronnimann <hbr -at- poly.edu>"
|
|
||||||
# MAINTAINERS
|
|
||||||
)
|
|
@ -28,6 +28,10 @@ namespace boost {
|
|||||||
|
|
||||||
// classification functors -----------------------------------------------//
|
// classification functors -----------------------------------------------//
|
||||||
|
|
||||||
|
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
|
||||||
|
#pragma warning(push)
|
||||||
|
#pragma warning(disable:4512) //assignment operator could not be generated
|
||||||
|
#endif
|
||||||
// is_classified functor
|
// is_classified functor
|
||||||
struct is_classifiedF :
|
struct is_classifiedF :
|
||||||
public predicate_facade<is_classifiedF>
|
public predicate_facade<is_classifiedF>
|
||||||
@ -38,6 +42,7 @@ namespace boost {
|
|||||||
// Constructor from a locale
|
// Constructor from a locale
|
||||||
is_classifiedF(std::ctype_base::mask Type, std::locale const & Loc = std::locale()) :
|
is_classifiedF(std::ctype_base::mask Type, std::locale const & Loc = std::locale()) :
|
||||||
m_Type(Type), m_Locale(Loc) {}
|
m_Type(Type), m_Locale(Loc) {}
|
||||||
|
|
||||||
// Operation
|
// Operation
|
||||||
template<typename CharT>
|
template<typename CharT>
|
||||||
bool operator()( CharT Ch ) const
|
bool operator()( CharT Ch ) const
|
||||||
@ -54,10 +59,13 @@ namespace boost {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::ctype_base::mask m_Type;
|
const std::ctype_base::mask m_Type;
|
||||||
std::locale m_Locale;
|
const std::locale m_Locale;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
|
||||||
|
#pragma warning(pop)
|
||||||
|
#endif
|
||||||
|
|
||||||
// is_any_of functor
|
// is_any_of functor
|
||||||
/*
|
/*
|
||||||
@ -69,7 +77,9 @@ namespace boost {
|
|||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
// set cannot operate on const value-type
|
// set cannot operate on const value-type
|
||||||
typedef typename ::boost::remove_const<CharT>::type set_value_type;
|
typedef typename remove_const<CharT>::type set_value_type;
|
||||||
|
// Size of the static storage (size of pointer*2)
|
||||||
|
static const ::std::size_t FIXED_STORAGE_SIZE = sizeof(set_value_type*)*2;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Boost.Lambda support
|
// Boost.Lambda support
|
||||||
@ -86,7 +96,7 @@ namespace boost {
|
|||||||
m_Size=Size;
|
m_Size=Size;
|
||||||
set_value_type* Storage=0;
|
set_value_type* Storage=0;
|
||||||
|
|
||||||
if(use_fixed_storage(m_Size))
|
if(m_Size<=FIXED_STORAGE_SIZE)
|
||||||
{
|
{
|
||||||
// Use fixed storage
|
// Use fixed storage
|
||||||
Storage=&m_Storage.m_fixSet[0];
|
Storage=&m_Storage.m_fixSet[0];
|
||||||
@ -111,7 +121,7 @@ namespace boost {
|
|||||||
const set_value_type* SrcStorage=0;
|
const set_value_type* SrcStorage=0;
|
||||||
set_value_type* DestStorage=0;
|
set_value_type* DestStorage=0;
|
||||||
|
|
||||||
if(use_fixed_storage(m_Size))
|
if(m_Size<=FIXED_STORAGE_SIZE)
|
||||||
{
|
{
|
||||||
// Use fixed storage
|
// Use fixed storage
|
||||||
DestStorage=&m_Storage.m_fixSet[0];
|
DestStorage=&m_Storage.m_fixSet[0];
|
||||||
@ -132,80 +142,36 @@ namespace boost {
|
|||||||
// Destructor
|
// Destructor
|
||||||
~is_any_ofF()
|
~is_any_ofF()
|
||||||
{
|
{
|
||||||
if(!use_fixed_storage(m_Size) && m_Storage.m_dynSet!=0)
|
if(m_Size>FIXED_STORAGE_SIZE && m_Storage.m_dynSet!=0)
|
||||||
{
|
{
|
||||||
delete [] m_Storage.m_dynSet;
|
delete m_Storage.m_dynSet;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assignment
|
// Assignment
|
||||||
is_any_ofF& operator=(const is_any_ofF& Other)
|
is_any_ofF& operator=(const is_any_ofF& Other)
|
||||||
{
|
{
|
||||||
// Handle self assignment
|
|
||||||
if(this==&Other) return *this;
|
|
||||||
|
|
||||||
// Prepare storage
|
// Prepare storage
|
||||||
const set_value_type* SrcStorage;
|
m_Storage.m_dynSet=0;
|
||||||
set_value_type* DestStorage;
|
m_Size=Other.m_Size;
|
||||||
|
const set_value_type* SrcStorage=0;
|
||||||
|
set_value_type* DestStorage=0;
|
||||||
|
|
||||||
if(use_fixed_storage(Other.m_Size))
|
if(m_Size<=FIXED_STORAGE_SIZE)
|
||||||
{
|
{
|
||||||
// Use fixed storage
|
// Use fixed storage
|
||||||
DestStorage=&m_Storage.m_fixSet[0];
|
DestStorage=&m_Storage.m_fixSet[0];
|
||||||
SrcStorage=&Other.m_Storage.m_fixSet[0];
|
SrcStorage=&Other.m_Storage.m_fixSet[0];
|
||||||
|
|
||||||
// Delete old storage if was present
|
|
||||||
if(!use_fixed_storage(m_Size) && m_Storage.m_dynSet!=0)
|
|
||||||
{
|
|
||||||
delete [] m_Storage.m_dynSet;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set new size
|
|
||||||
m_Size=Other.m_Size;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Other uses dynamic storage
|
// Use dynamic storage
|
||||||
SrcStorage=Other.m_Storage.m_dynSet;
|
m_Storage.m_dynSet=new set_value_type[m_Size];
|
||||||
|
|
||||||
// Check what kind of storage are we using right now
|
|
||||||
if(use_fixed_storage(m_Size))
|
|
||||||
{
|
|
||||||
// Using fixed storage, allocate new
|
|
||||||
set_value_type* pTemp=new set_value_type[Other.m_Size];
|
|
||||||
DestStorage=pTemp;
|
|
||||||
m_Storage.m_dynSet=pTemp;
|
|
||||||
m_Size=Other.m_Size;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Using dynamic storage, check if can reuse
|
|
||||||
if(m_Storage.m_dynSet!=0 && m_Size>=Other.m_Size && m_Size<Other.m_Size*2)
|
|
||||||
{
|
|
||||||
// Reuse the current storage
|
|
||||||
DestStorage=m_Storage.m_dynSet;
|
DestStorage=m_Storage.m_dynSet;
|
||||||
m_Size=Other.m_Size;
|
SrcStorage=Other.m_Storage.m_dynSet;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Allocate the new one
|
|
||||||
set_value_type* pTemp=new set_value_type[Other.m_Size];
|
|
||||||
DestStorage=pTemp;
|
|
||||||
|
|
||||||
// Delete old storage if necessary
|
|
||||||
if(m_Storage.m_dynSet!=0)
|
|
||||||
{
|
|
||||||
delete [] m_Storage.m_dynSet;
|
|
||||||
}
|
|
||||||
// Store the new storage
|
|
||||||
m_Storage.m_dynSet=pTemp;
|
|
||||||
// Set new size
|
|
||||||
m_Size=Other.m_Size;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy the data
|
// Use fixed storage
|
||||||
::memcpy(DestStorage, SrcStorage, sizeof(set_value_type)*m_Size);
|
::memcpy(DestStorage, SrcStorage, sizeof(set_value_type)*m_Size);
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
@ -216,19 +182,12 @@ namespace boost {
|
|||||||
bool operator()( Char2T Ch ) const
|
bool operator()( Char2T Ch ) const
|
||||||
{
|
{
|
||||||
const set_value_type* Storage=
|
const set_value_type* Storage=
|
||||||
(use_fixed_storage(m_Size))
|
(m_Size<=FIXED_STORAGE_SIZE)
|
||||||
? &m_Storage.m_fixSet[0]
|
? &m_Storage.m_fixSet[0]
|
||||||
: m_Storage.m_dynSet;
|
: m_Storage.m_dynSet;
|
||||||
|
|
||||||
return ::std::binary_search(Storage, Storage+m_Size, Ch);
|
return ::std::binary_search(Storage, Storage+m_Size, Ch);
|
||||||
}
|
}
|
||||||
private:
|
|
||||||
// check if the size is eligible for fixed storage
|
|
||||||
static bool use_fixed_storage(std::size_t size)
|
|
||||||
{
|
|
||||||
return size<=sizeof(set_value_type*)*2;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// storage
|
// storage
|
||||||
@ -236,7 +195,7 @@ namespace boost {
|
|||||||
union
|
union
|
||||||
{
|
{
|
||||||
set_value_type* m_dynSet;
|
set_value_type* m_dynSet;
|
||||||
set_value_type m_fixSet[sizeof(set_value_type*)*2];
|
set_value_type m_fixSet[FIXED_STORAGE_SIZE];
|
||||||
}
|
}
|
||||||
m_Storage;
|
m_Storage;
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ be enough. The present library solves both problems.</p>
|
|||||||
<tt>minmax</tt>
|
<tt>minmax</tt>
|
||||||
as straightforward extensions of the C++
|
as straightforward extensions of the C++
|
||||||
standard. As it returns a pair of <tt>const&</tt>, we must use the <a
|
standard. As it returns a pair of <tt>const&</tt>, we must use the <a
|
||||||
href=:../../../../tuple/index.html>Boost.tuple</a> library to construct such
|
href="../../tuple/index.html">Boost.tuple</a> library to construct such
|
||||||
pairs. (Please note: the intent is not to fix the known defaults of
|
pairs. (Please note: the intent is not to fix the known defaults of
|
||||||
<tt>std::min</tt>
|
<tt>std::min</tt>
|
||||||
and <tt>std::max</tt>, but to add one more algorithms that combines both; see the
|
and <tt>std::max</tt>, but to add one more algorithms that combines both; see the
|
||||||
|
@ -1,4 +0,0 @@
|
|||||||
boost_additional_test_dependencies(algorithm BOOST_DEPENDS test)
|
|
||||||
|
|
||||||
boost_test_run(minmax_element_test)
|
|
||||||
boost_test_run(minmax_test)
|
|
@ -1,4 +0,0 @@
|
|||||||
boost_module(algorithm DEPENDS regex concept_check range)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,12 +0,0 @@
|
|||||||
boost_additional_test_dependencies(algorithm BOOST_DEPENDS test)
|
|
||||||
|
|
||||||
|
|
||||||
boost_test_run(trim_test)
|
|
||||||
boost_test_run(conv_test)
|
|
||||||
boost_test_run(predicate_test)
|
|
||||||
boost_test_run(find_test)
|
|
||||||
boost_test_run(split_test)
|
|
||||||
boost_test_run(join_test)
|
|
||||||
boost_test_run(replace_test)
|
|
||||||
boost_test_run(regex_test DEPENDS boost_regex SHARED)
|
|
||||||
|
|
@ -96,29 +96,10 @@ void predicate_test()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Pred, typename Input>
|
|
||||||
void test_pred(const Pred& pred, const Input& input, bool bYes)
|
|
||||||
{
|
|
||||||
// test assignment operator
|
|
||||||
Pred pred1=pred;
|
|
||||||
pred1=pred;
|
|
||||||
pred1=pred1;
|
|
||||||
if(bYes)
|
|
||||||
{
|
|
||||||
BOOST_CHECK( all( input, pred ) );
|
|
||||||
BOOST_CHECK( all( input, pred1 ) );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
BOOST_CHECK( !all( input, pred ) );
|
|
||||||
BOOST_CHECK( !all( input, pred1 ) );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#define TEST_CLASS( Pred, YesInput, NoInput )\
|
#define TEST_CLASS( Pred, YesInput, NoInput )\
|
||||||
{\
|
{\
|
||||||
test_pred(Pred, YesInput, true); \
|
BOOST_CHECK( all( string(YesInput), Pred ) );\
|
||||||
test_pred(Pred, NoInput, false); \
|
BOOST_CHECK( !all( string(NoInput), Pred ) );\
|
||||||
}
|
}
|
||||||
|
|
||||||
void classification_test()
|
void classification_test()
|
||||||
|
Reference in New Issue
Block a user