Commit 8cd8dfaa authored by Davis King's avatar Davis King

Switched the std_vector_c object to use inheritance so that casting between

std_vector_c and std::vector is more natural.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%403384
parent 381cfb19
This diff is collapsed.
...@@ -14,7 +14,7 @@ namespace dlib ...@@ -14,7 +14,7 @@ namespace dlib
typename T, typename T,
typename Allocator = std::allocator<T> typename Allocator = std::allocator<T>
> >
class std_vector_c class std_vector_c : public std::vector<T,Allocator>
{ {
/*! /*!
WHAT THIS OBJECT REPRESENTS WHAT THIS OBJECT REPRESENTS
...@@ -75,14 +75,6 @@ namespace dlib ...@@ -75,14 +75,6 @@ namespace dlib
- std::equal(first, last, begin()) == true - std::equal(first, last, begin()) == true
!*/ !*/
std_vector_c(
const std_vector_c<T,Allocator>& x
);
/*!
ensures
- #*this == x
!*/
std_vector_c( std_vector_c(
const std::vector<T,Allocator>& x const std::vector<T,Allocator>& x
); );
...@@ -91,31 +83,6 @@ namespace dlib ...@@ -91,31 +83,6 @@ namespace dlib
- #*this == x - #*this == x
!*/ !*/
operator const std::vector<T,Allocator>& (
) const;
/*!
ensures
- returns a const reference to the normal unchecked std::vector
object contained inside *this
!*/
operator std::vector<T,Allocator>& (
);
/*!
ensures
- returns a non-const reference to the normal unchecked std::vector
object contained inside *this
!*/
std_vector_c<T,Allocator>& operator= (
const std_vector_c<T,Allocator>& x
);
/*!
ensures
- #*this == x
- returns #*this
!*/
std_vector_c<T,Allocator>& operator= ( std_vector_c<T,Allocator>& operator= (
const std::vector<T,Allocator>& x const std::vector<T,Allocator>& x
); );
...@@ -472,42 +439,6 @@ namespace dlib ...@@ -472,42 +439,6 @@ namespace dlib
}; };
// ----------------------------------------------------------------------------------------
// provide global comparison operators that work for the std_vector_c object.
template <typename T, typename Allocator>
bool operator==(const std_vector_c<T,Allocator>& x, const std_vector_c<T,Allocator>& y)
{ return x.size() == y.size() && std::equal(x.begin(), x.end(), y.begin()); }
template <typename T, typename Allocator>
bool operator< (const std_vector_c<T,Allocator>& x, const std_vector_c<T,Allocator>& y)
{ return std::lexicographical_compare(x.begin(), x.end(), y.begin(), y.end()); }
template <typename T, typename Allocator>
bool operator!=(const std_vector_c<T,Allocator>& x, const std_vector_c<T,Allocator>& y)
{ return !(x == y); }
template <typename T, typename Allocator>
bool operator> (const std_vector_c<T,Allocator>& x, const std_vector_c<T,Allocator>& y)
{ return y < x; }
template <typename T, typename Allocator>
bool operator>=(const std_vector_c<T,Allocator>& x, const std_vector_c<T,Allocator>& y)
{ return !(x < y); }
template <typename T, typename Allocator>
bool operator<=(const std_vector_c<T,Allocator>& x, const std_vector_c<T,Allocator>& y)
{ return !(y < x); }
// ----------------------------------------------------------------------------------------
template <typename T, typename Allocator>
void swap(std_vector_c<T,Allocator>& x, std_vector_c<T,Allocator>& y) { x.swap(y); }
/*!
provides a global swap function
!*/
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
template <typename T, typename alloc> template <typename T, typename alloc>
......
...@@ -74,6 +74,7 @@ set (tests ...@@ -74,6 +74,7 @@ set (tests
stack.cpp stack.cpp
static_map.cpp static_map.cpp
static_set.cpp static_set.cpp
std_vector_c.cpp
string.cpp string.cpp
svm.cpp svm.cpp
thread_pool.cpp thread_pool.cpp
......
...@@ -84,6 +84,7 @@ SRC += sockstreambuf.cpp ...@@ -84,6 +84,7 @@ SRC += sockstreambuf.cpp
SRC += stack.cpp SRC += stack.cpp
SRC += static_map.cpp SRC += static_map.cpp
SRC += static_set.cpp SRC += static_set.cpp
SRC += std_vector_c.cpp
SRC += string.cpp SRC += string.cpp
SRC += svm.cpp SRC += svm.cpp
SRC += thread_pool.cpp SRC += thread_pool.cpp
......
// Copyright (C) 2010 Davis E. King (davisking@users.sourceforge.net)
// License: Boost Software License See LICENSE.txt for the full license.
#include <sstream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <dlib/stl_checked.h>
#include "tester.h"
// This is called an unnamed-namespace and it has the effect of making everything inside this file "private"
// so that everything you declare will have static linkage. Thus we won't have any multiply
// defined symbol errors coming out of the linker when we try to compile the test suite.
namespace
{
using namespace test;
using namespace dlib;
using namespace std;
// Declare the logger we will use in this test. The name of the tester
// should start with "test."
logger dlog("test.std_vector_c");
class std_vector_c_tester : public tester
{
/*!
WHAT THIS OBJECT REPRESENTS
This object represents a test for the std_vector_c object. When it is constructed
it adds itself into the testing framework. The command line switch is
specified as test_std_vector_c by passing that string to the tester constructor.
!*/
public:
std_vector_c_tester (
) :
tester ("test_std_vector_c",
"Runs tests on the std_vector_c component.")
{}
void perform_test (
)
{
std::vector<int> c;
std_vector_c<int> a, b;
a.push_back(3);
a.push_back(2);
a.push_back(1);
DLIB_TEST(a[0] == 3);
DLIB_TEST(a[1] == 2);
DLIB_TEST(a[2] == 1);
c = a;
DLIB_TEST(c[0] == 3);
DLIB_TEST(c[1] == 2);
DLIB_TEST(c[2] == 1);
DLIB_TEST(c.size() == 3);
DLIB_TEST(a.size() == 3);
DLIB_TEST(b.size() == 0);
DLIB_TEST(a == c);
DLIB_TEST(!(a != c));
DLIB_TEST(a <= c);
DLIB_TEST(a >= c);
DLIB_TEST(!(a < c));
DLIB_TEST(!(a > c));
swap(b,c);
DLIB_TEST(b[0] == 3);
DLIB_TEST(b[1] == 2);
DLIB_TEST(b[2] == 1);
DLIB_TEST(c.size() == 0);
DLIB_TEST(b.size() == 3);
swap(c,b);
DLIB_TEST(c[0] == 3);
DLIB_TEST(c[1] == 2);
DLIB_TEST(c[2] == 1);
DLIB_TEST(c.size() == 3);
DLIB_TEST(b.size() == 0);
swap(a,b);
DLIB_TEST(b[0] == 3);
DLIB_TEST(b[1] == 2);
DLIB_TEST(b[2] == 1);
DLIB_TEST(b.size() == 3);
DLIB_TEST(a.size() == 0);
swap(b,c);
swap(c,c);
std_vector_c<int> h(a);
std_vector_c<int> i(c);
std::vector<int> j(b);
}
} a;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment