mirror of
https://github.com/boostorg/algorithm.git
synced 2025-06-26 12:31:44 +02:00
Compare commits
10 Commits
svn-branch
...
sandbox-br
Author | SHA1 | Date | |
---|---|---|---|
2915f87820 | |||
e8a2596637 | |||
7b2754b937 | |||
784402e5c0 | |||
1188575e7b | |||
bff2a1e112 | |||
6d5e7b5a04 | |||
760af1798b | |||
1f5542b44c | |||
baf3dd99e2 |
20
CMakeLists.txt
Normal file
20
CMakeLists.txt
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#----------------------------------------------------------------------------
|
||||||
|
# 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,11 +28,7 @@ namespace boost {
|
|||||||
|
|
||||||
// classification functors -----------------------------------------------//
|
// classification functors -----------------------------------------------//
|
||||||
|
|
||||||
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
|
// is_classified functor
|
||||||
#pragma warning(push)
|
|
||||||
#pragma warning(disable:4512) //assignment operator could not be generated
|
|
||||||
#endif
|
|
||||||
// is_classified functor
|
|
||||||
struct is_classifiedF :
|
struct is_classifiedF :
|
||||||
public predicate_facade<is_classifiedF>
|
public predicate_facade<is_classifiedF>
|
||||||
{
|
{
|
||||||
@ -42,7 +38,6 @@ 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
|
||||||
@ -59,13 +54,10 @@ namespace boost {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const std::ctype_base::mask m_Type;
|
std::ctype_base::mask m_Type;
|
||||||
const std::locale m_Locale;
|
std::locale m_Locale;
|
||||||
};
|
};
|
||||||
|
|
||||||
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
|
|
||||||
#pragma warning(pop)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// is_any_of functor
|
// is_any_of functor
|
||||||
/*
|
/*
|
||||||
@ -77,9 +69,7 @@ namespace boost {
|
|||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
// set cannot operate on const value-type
|
// set cannot operate on const value-type
|
||||||
typedef typename remove_const<CharT>::type set_value_type;
|
typedef typename ::boost::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
|
||||||
@ -96,7 +86,7 @@ namespace boost {
|
|||||||
m_Size=Size;
|
m_Size=Size;
|
||||||
set_value_type* Storage=0;
|
set_value_type* Storage=0;
|
||||||
|
|
||||||
if(m_Size<=FIXED_STORAGE_SIZE)
|
if(use_fixed_storage(m_Size))
|
||||||
{
|
{
|
||||||
// Use fixed storage
|
// Use fixed storage
|
||||||
Storage=&m_Storage.m_fixSet[0];
|
Storage=&m_Storage.m_fixSet[0];
|
||||||
@ -121,7 +111,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(m_Size<=FIXED_STORAGE_SIZE)
|
if(use_fixed_storage(m_Size))
|
||||||
{
|
{
|
||||||
// Use fixed storage
|
// Use fixed storage
|
||||||
DestStorage=&m_Storage.m_fixSet[0];
|
DestStorage=&m_Storage.m_fixSet[0];
|
||||||
@ -142,36 +132,80 @@ namespace boost {
|
|||||||
// Destructor
|
// Destructor
|
||||||
~is_any_ofF()
|
~is_any_ofF()
|
||||||
{
|
{
|
||||||
if(m_Size>FIXED_STORAGE_SIZE && m_Storage.m_dynSet!=0)
|
if(!use_fixed_storage(m_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)
|
||||||
{
|
{
|
||||||
// Prepare storage
|
// Handle self assignment
|
||||||
m_Storage.m_dynSet=0;
|
if(this==&Other) return *this;
|
||||||
m_Size=Other.m_Size;
|
|
||||||
const set_value_type* SrcStorage=0;
|
|
||||||
set_value_type* DestStorage=0;
|
|
||||||
|
|
||||||
if(m_Size<=FIXED_STORAGE_SIZE)
|
// Prepare storage
|
||||||
|
const set_value_type* SrcStorage;
|
||||||
|
set_value_type* DestStorage;
|
||||||
|
|
||||||
|
if(use_fixed_storage(Other.m_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
|
||||||
{
|
{
|
||||||
// Use dynamic storage
|
// Other uses dynamic storage
|
||||||
m_Storage.m_dynSet=new set_value_type[m_Size];
|
|
||||||
DestStorage=m_Storage.m_dynSet;
|
|
||||||
SrcStorage=Other.m_Storage.m_dynSet;
|
SrcStorage=Other.m_Storage.m_dynSet;
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
m_Size=Other.m_Size;
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use fixed storage
|
// Copy the data
|
||||||
::memcpy(DestStorage, SrcStorage, sizeof(set_value_type)*m_Size);
|
::memcpy(DestStorage, SrcStorage, sizeof(set_value_type)*m_Size);
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
@ -182,12 +216,19 @@ namespace boost {
|
|||||||
bool operator()( Char2T Ch ) const
|
bool operator()( Char2T Ch ) const
|
||||||
{
|
{
|
||||||
const set_value_type* Storage=
|
const set_value_type* Storage=
|
||||||
(m_Size<=FIXED_STORAGE_SIZE)
|
(use_fixed_storage(m_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
|
||||||
@ -195,7 +236,7 @@ namespace boost {
|
|||||||
union
|
union
|
||||||
{
|
{
|
||||||
set_value_type* m_dynSet;
|
set_value_type* m_dynSet;
|
||||||
set_value_type m_fixSet[FIXED_STORAGE_SIZE];
|
set_value_type m_fixSet[sizeof(set_value_type*)*2];
|
||||||
}
|
}
|
||||||
m_Storage;
|
m_Storage;
|
||||||
|
|
||||||
|
@ -158,9 +158,9 @@ identical to
|
|||||||
that they return the last instance of the largest element (and not the
|
that they return the last instance of the largest element (and not the
|
||||||
first, as <tt>first_min_element</tt> and <tt>last_max_element</tt> would).
|
first, as <tt>first_min_element</tt> and <tt>last_max_element</tt> would).
|
||||||
<p>The family of algorithms comprising <tt>first_min_first_max_element</tt>,
|
<p>The family of algorithms comprising <tt>first_min_first_max_element</tt>,
|
||||||
<tt>first_min_first_max_element</tt>,
|
<tt>first_min_last_max_element</tt>,
|
||||||
<tt>first_min_first_max_element</tt>,
|
<tt>last_min_first_max_element</tt>,
|
||||||
and <tt>first_min_first_max_element</tt> can be described generically as
|
and <tt>last_min_last_max_element</tt> can be described generically as
|
||||||
follows (using <i><tt>which</tt></i> and
|
follows (using <i><tt>which</tt></i> and
|
||||||
<i><tt>what</tt></i> for <tt>first</tt>
|
<i><tt>what</tt></i> for <tt>first</tt>
|
||||||
or <tt>last</tt>): <tt><i>which</i>_min_<i>what</i>_max_element</tt> finds
|
or <tt>last</tt>): <tt><i>which</i>_min_<i>what</i>_max_element</tt> finds
|
||||||
|
4
minmax/test/CMakeLists.txt
Normal file
4
minmax/test/CMakeLists.txt
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
boost_additional_test_dependencies(algorithm BOOST_DEPENDS test)
|
||||||
|
|
||||||
|
boost_test_run(minmax_element_test)
|
||||||
|
boost_test_run(minmax_test)
|
4
module.cmake
Normal file
4
module.cmake
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
boost_module(algorithm DEPENDS regex concept_check range)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -10,7 +10,10 @@
|
|||||||
import toolset ;
|
import toolset ;
|
||||||
toolset.using doxygen ;
|
toolset.using doxygen ;
|
||||||
|
|
||||||
boostbook string_algo : string_algo.xml autodoc ;
|
boostbook string_algo : string_algo.xml autodoc
|
||||||
|
:
|
||||||
|
<format>pdf:<xsl:param>boost.url.prefix=http://www.boost.org/doc/libs/release/doc/html
|
||||||
|
;
|
||||||
|
|
||||||
doxygen autodoc
|
doxygen autodoc
|
||||||
:
|
:
|
||||||
|
12
string/test/CMakeLists.txt
Normal file
12
string/test/CMakeLists.txt
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
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,10 +96,29 @@ 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 )\
|
||||||
{\
|
{\
|
||||||
BOOST_CHECK( all( string(YesInput), Pred ) );\
|
test_pred(Pred, YesInput, true); \
|
||||||
BOOST_CHECK( !all( string(NoInput), Pred ) );\
|
test_pred(Pred, NoInput, false); \
|
||||||
}
|
}
|
||||||
|
|
||||||
void classification_test()
|
void classification_test()
|
||||||
|
Reference in New Issue
Block a user