diff --git a/include/tesseract/genericvector.h b/include/tesseract/genericvector.h index 3a651c5271..846e0f8d6e 100644 --- a/include/tesseract/genericvector.h +++ b/include/tesseract/genericvector.h @@ -37,9 +37,20 @@ namespace tesseract { // sort that works. template class GenericVector : public std::vector { + using base = std::vector; public: using std::vector::vector; + using base::begin; + using base::end; + using base::data; + using base::capacity; + using base::reserve; + using base::resize; + using base::back; + using base::clear; + using base::push_back; + GenericVector& operator+=(const GenericVector& other); // Double the size of the internal array. @@ -61,7 +72,7 @@ class GenericVector : public std::vector { } int size() const { - return vector::size(); + return base::size(); } // Return the object from an index. @@ -442,7 +453,7 @@ class PointerVector : public GenericVector { delete GenericVector::data()[old_index]; } } - resize(new_size); + GenericVector::resize(new_size); } // Clear the array, calling the clear callback function if any. @@ -650,7 +661,7 @@ const T& GenericVector::get(int index) const { template T GenericVector::pop_back() { auto b = back(); - vector::pop_back(); + base::pop_back(); return b; } @@ -666,7 +677,7 @@ void GenericVector::set(const T& t, int index) { // at the specified index. template void GenericVector::insert(const T& t, int index) { - vector::insert(begin() + index, t); + base::insert(begin() + index, t); } // Removes an element at the given index and diff --git a/src/api/baseapi.cpp b/src/api/baseapi.cpp index 5fea2979e1..997038f66c 100644 --- a/src/api/baseapi.cpp +++ b/src/api/baseapi.cpp @@ -129,7 +129,9 @@ const int kMaxIntSize = 22; static void addAvailableLanguages(const STRING &datadir, const STRING &base, GenericVector* langs) { - const STRING base2 = (base.c_str()[0] == '\0') ? base : base + "/"; + auto base2 = base; + if (!base2.empty()) + base2 += "/"; const size_t extlen = sizeof(kTrainedDataSuffix); #ifdef _WIN32 WIN32_FIND_DATA data; diff --git a/src/ccutil/kdpair.h b/src/ccutil/kdpair.h index c26247aca8..db859429fd 100644 --- a/src/ccutil/kdpair.h +++ b/src/ccutil/kdpair.h @@ -34,9 +34,14 @@ namespace tesseract { // A useful base struct to facilitate the common operation of sorting a vector // of simple or smart-pointer data using a separate key. Similar to STL pair. template -struct KDPair : public std::pair { +class KDPair : public std::pair { + using base = std::pair; + public: using std::pair::pair; + using base::first; + using base::second; + int operator==(const KDPair& other) const { return first == other.first; } @@ -58,7 +63,8 @@ struct KDPair : public std::pair { // Specialization of KDPair to provide operator< for sorting in increasing order // and recasting of data pointers for use with DoublePtr. template -struct KDPairInc : public KDPair { +class KDPairInc : public KDPair { + public: using KDPair::KDPair; // Operator< facilitates sorting in increasing order. @@ -70,7 +76,8 @@ struct KDPairInc : public KDPair { // Specialization of KDPair to provide operator< for sorting in decreasing order // and recasting of data pointers for use with DoublePtr. template -struct KDPairDec : public KDPair { +class KDPairDec : public KDPair { + public: using KDPair::KDPair; // Operator< facilitates sorting in decreasing order by using operator> on @@ -87,14 +94,18 @@ struct KDPairDec : public KDPair { // only a single instance of KDPtrPair holds a specific data pointer. template class KDPtrPair : public std::pair> { + using base = std::pair>; public: + using base::first; + using base::second; + KDPtrPair() = default; KDPtrPair(Key k, Data* d) : std::pair>(k, d) {} KDPtrPair(KDPtrPair &&src) = default; KDPtrPair &operator=(KDPtrPair &&src) = default; int operator==(const KDPtrPair& other) const { - return key_ == other.key_; + return key() == other.key(); } // Accessors.