mirror of
https://github.com/boostorg/algorithm.git
synced 2025-07-06 09:16:33 +02:00
Tabs. I likes them; the inspect tool, not so much
[SVN r79590]
This commit is contained in:
@ -7,43 +7,43 @@
|
||||
Alternate interfaces (aka "wrappers") for algorithms.
|
||||
*/
|
||||
|
||||
#ifndef BOOST_ALGORITHM_WRAPPERS_HPP
|
||||
#define BOOST_ALGORITHM_WRAPPERS_HPP
|
||||
#ifndef BOOST_ALGORITHM_WRAPPERS_HPP
|
||||
#define BOOST_ALGORITHM_WRAPPERS_HPP
|
||||
|
||||
namespace boost { namespace algorithm {
|
||||
|
||||
/// \fn find_ptr ( Container &c, Key k )
|
||||
/// \return a pointer to the value matching the key in the container,
|
||||
/// or NULL if the key does not exist in the container.
|
||||
/// or NULL if the key does not exist in the container.
|
||||
///
|
||||
/// \note: This is a wrapper around Container::find, with a useful interface.
|
||||
/// Suggested by Olaf van der Spek
|
||||
/// \note: This is a wrapper around Container::find, with a useful interface.
|
||||
/// Suggested by Olaf van der Spek
|
||||
///
|
||||
/// \param c The container to be searched
|
||||
/// \param k The key value to search with
|
||||
/// \param k The key value to search with
|
||||
template <class Container, class Key>
|
||||
typename Container::value_type::second_type*
|
||||
find_ptr ( Container &c, Key k )
|
||||
{
|
||||
typename Container::iterator iter = c.find ( k );
|
||||
return iter == c.end() ? NULL : &iter->second;
|
||||
typename Container::iterator iter = c.find ( k );
|
||||
return iter == c.end() ? NULL : &iter->second;
|
||||
}
|
||||
|
||||
/// \fn find_ptr ( const Container &c, Key k )
|
||||
/// \return a pointer to the value matching the key in the container,
|
||||
/// or NULL if the key does not exist in the container.
|
||||
/// or NULL if the key does not exist in the container.
|
||||
///
|
||||
/// \note: This is a wrapper around Container::find, with a useful interface.
|
||||
/// Suggested by Olaf van der Spek
|
||||
/// \note: This is a wrapper around Container::find, with a useful interface.
|
||||
/// Suggested by Olaf van der Spek
|
||||
///
|
||||
/// \param c The container to be searched
|
||||
/// \param k The key value to search with
|
||||
/// \param k The key value to search with
|
||||
template <class Container, class Key>
|
||||
const typename Container::value_type::second_type*
|
||||
find_ptr ( const Container &c, Key k )
|
||||
{
|
||||
typename Container::const_iterator iter = c.find ( k );
|
||||
return iter == c.end() ? NULL : &iter->second;
|
||||
typename Container::const_iterator iter = c.find ( k );
|
||||
return iter == c.end() ? NULL : &iter->second;
|
||||
}
|
||||
|
||||
|
||||
|
@ -19,127 +19,127 @@ Try ostream_iterators
|
||||
namespace ba = boost::algorithm;
|
||||
|
||||
void test_short_input1 () {
|
||||
std::string s;
|
||||
std::string s;
|
||||
|
||||
try { ba::unhex ( std::string ( "A" ), std::back_inserter(s)); }
|
||||
catch ( const std::exception &ex ) { return; }
|
||||
BOOST_TEST_MESSAGE ( "Failed to catch std::exception in test_short_input1" );
|
||||
BOOST_CHECK ( false );
|
||||
}
|
||||
try { ba::unhex ( std::string ( "A" ), std::back_inserter(s)); }
|
||||
catch ( const std::exception &ex ) { return; }
|
||||
BOOST_TEST_MESSAGE ( "Failed to catch std::exception in test_short_input1" );
|
||||
BOOST_CHECK ( false );
|
||||
}
|
||||
|
||||
void test_short_input2 () {
|
||||
std::string s;
|
||||
std::string s;
|
||||
|
||||
try { ba::unhex ( std::string ( "A" ), std::back_inserter(s)); }
|
||||
catch ( const ba::hex_decode_error &ex ) { return; }
|
||||
BOOST_TEST_MESSAGE ( "Failed to catch ba::hex_decode_error in test_short_input2" );
|
||||
BOOST_CHECK ( false );
|
||||
}
|
||||
try { ba::unhex ( std::string ( "A" ), std::back_inserter(s)); }
|
||||
catch ( const ba::hex_decode_error &ex ) { return; }
|
||||
BOOST_TEST_MESSAGE ( "Failed to catch ba::hex_decode_error in test_short_input2" );
|
||||
BOOST_CHECK ( false );
|
||||
}
|
||||
|
||||
void test_short_input3 () {
|
||||
std::string s;
|
||||
std::string s;
|
||||
|
||||
try { ba::unhex ( std::string ( "A" ), std::back_inserter(s)); }
|
||||
catch ( const ba::not_enough_input &ex ) { return; }
|
||||
BOOST_TEST_MESSAGE ( "Failed to catch ba::not_enough_input in test_short_input3" );
|
||||
BOOST_CHECK ( false );
|
||||
}
|
||||
try { ba::unhex ( std::string ( "A" ), std::back_inserter(s)); }
|
||||
catch ( const ba::not_enough_input &ex ) { return; }
|
||||
BOOST_TEST_MESSAGE ( "Failed to catch ba::not_enough_input in test_short_input3" );
|
||||
BOOST_CHECK ( false );
|
||||
}
|
||||
|
||||
// Make sure that the right thing is thrown
|
||||
// Make sure that the right thing is thrown
|
||||
void test_short_input4 () {
|
||||
std::string s;
|
||||
std::string s;
|
||||
|
||||
try { ba::unhex ( std::string ( "A" ), std::back_inserter(s)); }
|
||||
catch ( const ba::non_hex_input &ex ) { BOOST_CHECK ( false ); }
|
||||
catch ( const ba::not_enough_input &ex ) { return; }
|
||||
catch ( ... ) { BOOST_CHECK ( false ); }
|
||||
BOOST_CHECK ( false );
|
||||
}
|
||||
try { ba::unhex ( std::string ( "A" ), std::back_inserter(s)); }
|
||||
catch ( const ba::non_hex_input &ex ) { BOOST_CHECK ( false ); }
|
||||
catch ( const ba::not_enough_input &ex ) { return; }
|
||||
catch ( ... ) { BOOST_CHECK ( false ); }
|
||||
BOOST_CHECK ( false );
|
||||
}
|
||||
|
||||
// Make sure that the right thing is thrown
|
||||
// Make sure that the right thing is thrown
|
||||
void test_short_input5 () {
|
||||
std::string s;
|
||||
std::string s;
|
||||
|
||||
try { ba::unhex ( "A", std::back_inserter(s)); }
|
||||
catch ( const ba::non_hex_input &ex ) { BOOST_CHECK ( false ); }
|
||||
catch ( const ba::not_enough_input &ex ) { return; }
|
||||
catch ( ... ) { BOOST_CHECK ( false ); }
|
||||
BOOST_CHECK ( false );
|
||||
}
|
||||
try { ba::unhex ( "A", std::back_inserter(s)); }
|
||||
catch ( const ba::non_hex_input &ex ) { BOOST_CHECK ( false ); }
|
||||
catch ( const ba::not_enough_input &ex ) { return; }
|
||||
catch ( ... ) { BOOST_CHECK ( false ); }
|
||||
BOOST_CHECK ( false );
|
||||
}
|
||||
|
||||
|
||||
void test_short_input () {
|
||||
// BOOST_TEST_MESSAGE ( "Short input tests for boost::algorithm::unhex" );
|
||||
test_short_input1 ();
|
||||
test_short_input2 ();
|
||||
test_short_input3 ();
|
||||
test_short_input4 ();
|
||||
test_short_input5 ();
|
||||
}
|
||||
// BOOST_TEST_MESSAGE ( "Short input tests for boost::algorithm::unhex" );
|
||||
test_short_input1 ();
|
||||
test_short_input2 ();
|
||||
test_short_input3 ();
|
||||
test_short_input4 ();
|
||||
test_short_input5 ();
|
||||
}
|
||||
|
||||
|
||||
void test_nonhex_input1 () {
|
||||
std::string s;
|
||||
std::string s;
|
||||
|
||||
try { ba::unhex ( "01234FG1234", std::back_inserter(s)); }
|
||||
catch ( const std::exception &ex ) {
|
||||
BOOST_CHECK ( 'G' == *boost::get_error_info<ba::bad_char>(ex));
|
||||
return;
|
||||
}
|
||||
catch ( ... ) {}
|
||||
BOOST_TEST_MESSAGE ( "Failed to catch std::exception in test_nonhex_input1" );
|
||||
BOOST_CHECK ( false );
|
||||
}
|
||||
try { ba::unhex ( "01234FG1234", std::back_inserter(s)); }
|
||||
catch ( const std::exception &ex ) {
|
||||
BOOST_CHECK ( 'G' == *boost::get_error_info<ba::bad_char>(ex));
|
||||
return;
|
||||
}
|
||||
catch ( ... ) {}
|
||||
BOOST_TEST_MESSAGE ( "Failed to catch std::exception in test_nonhex_input1" );
|
||||
BOOST_CHECK ( false );
|
||||
}
|
||||
|
||||
void test_nonhex_input2 () {
|
||||
std::string s;
|
||||
std::string s;
|
||||
|
||||
try { ba::unhex ( "012Z4FA1234", std::back_inserter(s)); }
|
||||
catch ( const ba::hex_decode_error &ex ) {
|
||||
BOOST_CHECK ( 'Z' == *boost::get_error_info<ba::bad_char>(ex));
|
||||
return;
|
||||
}
|
||||
catch ( ... ) {}
|
||||
BOOST_TEST_MESSAGE ( "Failed to catch ba::hex_decode_error in test_nonhex_input2" );
|
||||
BOOST_CHECK ( false );
|
||||
}
|
||||
try { ba::unhex ( "012Z4FA1234", std::back_inserter(s)); }
|
||||
catch ( const ba::hex_decode_error &ex ) {
|
||||
BOOST_CHECK ( 'Z' == *boost::get_error_info<ba::bad_char>(ex));
|
||||
return;
|
||||
}
|
||||
catch ( ... ) {}
|
||||
BOOST_TEST_MESSAGE ( "Failed to catch ba::hex_decode_error in test_nonhex_input2" );
|
||||
BOOST_CHECK ( false );
|
||||
}
|
||||
|
||||
void test_nonhex_input3 () {
|
||||
std::string s;
|
||||
std::string s;
|
||||
|
||||
try { ba::unhex ( "01234FA12Q4", std::back_inserter(s)); }
|
||||
catch ( const ba::non_hex_input &ex ) {
|
||||
BOOST_CHECK ( 'Q' == *boost::get_error_info<ba::bad_char>(ex));
|
||||
return;
|
||||
}
|
||||
catch ( ... ) {}
|
||||
BOOST_TEST_MESSAGE ( "Failed to catch ba::non_hex_input in test_nonhex_input3" );
|
||||
BOOST_CHECK ( false );
|
||||
}
|
||||
try { ba::unhex ( "01234FA12Q4", std::back_inserter(s)); }
|
||||
catch ( const ba::non_hex_input &ex ) {
|
||||
BOOST_CHECK ( 'Q' == *boost::get_error_info<ba::bad_char>(ex));
|
||||
return;
|
||||
}
|
||||
catch ( ... ) {}
|
||||
BOOST_TEST_MESSAGE ( "Failed to catch ba::non_hex_input in test_nonhex_input3" );
|
||||
BOOST_CHECK ( false );
|
||||
}
|
||||
|
||||
// Make sure that the right thing is thrown
|
||||
// Make sure that the right thing is thrown
|
||||
void test_nonhex_input4 () {
|
||||
std::string s;
|
||||
std::string s;
|
||||
|
||||
try { ba::unhex ( "P1234FA1234", std::back_inserter(s)); }
|
||||
catch ( const ba::not_enough_input &ex ) { BOOST_CHECK ( false ); }
|
||||
catch ( const ba::non_hex_input &ex ) { return; }
|
||||
catch ( ... ) { BOOST_CHECK ( false ); }
|
||||
BOOST_CHECK ( false );
|
||||
}
|
||||
try { ba::unhex ( "P1234FA1234", std::back_inserter(s)); }
|
||||
catch ( const ba::not_enough_input &ex ) { BOOST_CHECK ( false ); }
|
||||
catch ( const ba::non_hex_input &ex ) { return; }
|
||||
catch ( ... ) { BOOST_CHECK ( false ); }
|
||||
BOOST_CHECK ( false );
|
||||
}
|
||||
|
||||
void test_nonhex_input () {
|
||||
// BOOST_TEST_MESSAGE ( "Non hex input tests for for boost::algorithm::unhex" );
|
||||
test_nonhex_input1 ();
|
||||
test_nonhex_input2 ();
|
||||
test_nonhex_input3 ();
|
||||
test_nonhex_input4 ();
|
||||
}
|
||||
// BOOST_TEST_MESSAGE ( "Non hex input tests for for boost::algorithm::unhex" );
|
||||
test_nonhex_input1 ();
|
||||
test_nonhex_input2 ();
|
||||
test_nonhex_input3 ();
|
||||
test_nonhex_input4 ();
|
||||
}
|
||||
|
||||
int test_main( int , char* [] )
|
||||
{
|
||||
test_short_input ();
|
||||
test_nonhex_input ();
|
||||
test_short_input ();
|
||||
test_nonhex_input ();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -19,52 +19,52 @@ namespace ba = boost::algorithm;
|
||||
|
||||
void test_int ()
|
||||
{
|
||||
std::map<int, int> m;
|
||||
std::multimap<int, int> mm;
|
||||
std::map<int, int> m;
|
||||
std::multimap<int, int> mm;
|
||||
|
||||
int *ptr;
|
||||
int *ptr;
|
||||
|
||||
// try with an empty map
|
||||
BOOST_CHECK ( ba::find_ptr ( m , 3 ) == NULL );
|
||||
BOOST_CHECK ( ba::find_ptr ( mm, 3 ) == NULL );
|
||||
// try with an empty map
|
||||
BOOST_CHECK ( ba::find_ptr ( m , 3 ) == NULL );
|
||||
BOOST_CHECK ( ba::find_ptr ( mm, 3 ) == NULL );
|
||||
|
||||
m.insert ( std::make_pair <int, int> ( 5, 5 ));
|
||||
mm.insert ( std::make_pair <int, int> ( 9, 9 ));
|
||||
BOOST_CHECK ( ba::find_ptr ( m , 3 ) == NULL );
|
||||
BOOST_CHECK ( ba::find_ptr ( mm, 3 ) == NULL );
|
||||
m.insert ( std::make_pair <int, int> ( 5, 5 ));
|
||||
mm.insert ( std::make_pair <int, int> ( 9, 9 ));
|
||||
BOOST_CHECK ( ba::find_ptr ( m , 3 ) == NULL );
|
||||
BOOST_CHECK ( ba::find_ptr ( mm, 3 ) == NULL );
|
||||
|
||||
ptr = ba::find_ptr ( m, 5 );
|
||||
BOOST_CHECK ( ptr != NULL && *ptr == 5 );
|
||||
BOOST_CHECK ( ba::find_ptr ( m , 9 ) == NULL );
|
||||
ptr = ba::find_ptr ( m, 5 );
|
||||
BOOST_CHECK ( ptr != NULL && *ptr == 5 );
|
||||
BOOST_CHECK ( ba::find_ptr ( m , 9 ) == NULL );
|
||||
|
||||
ptr = ba::find_ptr ( mm, 9 );
|
||||
BOOST_CHECK ( ptr != NULL && *ptr == 9 );
|
||||
BOOST_CHECK ( ba::find_ptr ( mm, 5 ) == NULL );
|
||||
ptr = ba::find_ptr ( mm, 9 );
|
||||
BOOST_CHECK ( ptr != NULL && *ptr == 9 );
|
||||
BOOST_CHECK ( ba::find_ptr ( mm, 5 ) == NULL );
|
||||
|
||||
}
|
||||
|
||||
void test_str ()
|
||||
{
|
||||
std::map<int, std::string> m;
|
||||
std::multimap<int, std::string> mm;
|
||||
std::string *ptr;
|
||||
std::map<int, std::string> m;
|
||||
std::multimap<int, std::string> mm;
|
||||
std::string *ptr;
|
||||
|
||||
// try with an empty map
|
||||
BOOST_CHECK ( ba::find_ptr ( m , 31 ) == NULL );
|
||||
BOOST_CHECK ( ba::find_ptr ( mm, 31 ) == NULL );
|
||||
// try with an empty map
|
||||
BOOST_CHECK ( ba::find_ptr ( m , 31 ) == NULL );
|
||||
BOOST_CHECK ( ba::find_ptr ( mm, 31 ) == NULL );
|
||||
|
||||
m.insert ( std::make_pair <int, std::string> ( 55, "fifty-five" ));
|
||||
mm.insert ( std::make_pair <int, std::string> ( 66, "sixty-six" ));
|
||||
BOOST_CHECK ( ba::find_ptr ( m , 3 ) == NULL );
|
||||
BOOST_CHECK ( ba::find_ptr ( mm, 3 ) == NULL );
|
||||
m.insert ( std::make_pair <int, std::string> ( 55, "fifty-five" ));
|
||||
mm.insert ( std::make_pair <int, std::string> ( 66, "sixty-six" ));
|
||||
BOOST_CHECK ( ba::find_ptr ( m , 3 ) == NULL );
|
||||
BOOST_CHECK ( ba::find_ptr ( mm, 3 ) == NULL );
|
||||
|
||||
ptr = ba::find_ptr ( m, 55 );
|
||||
BOOST_CHECK ( ptr != NULL && *ptr == "fifty-five" );
|
||||
BOOST_CHECK ( ba::find_ptr ( m , 66 ) == NULL );
|
||||
ptr = ba::find_ptr ( m, 55 );
|
||||
BOOST_CHECK ( ptr != NULL && *ptr == "fifty-five" );
|
||||
BOOST_CHECK ( ba::find_ptr ( m , 66 ) == NULL );
|
||||
|
||||
ptr = ba::find_ptr ( mm, 66 );
|
||||
BOOST_CHECK ( ptr != NULL && *ptr == "sixty-six" );
|
||||
BOOST_CHECK ( ba::find_ptr ( mm, 55 ) == NULL );
|
||||
ptr = ba::find_ptr ( mm, 66 );
|
||||
BOOST_CHECK ( ptr != NULL && *ptr == "sixty-six" );
|
||||
BOOST_CHECK ( ba::find_ptr ( mm, 55 ) == NULL );
|
||||
}
|
||||
|
||||
int test_main( int , char* [] )
|
||||
|
Reference in New Issue
Block a user