-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
Description
Overview
This issue tracks modernizing the TOL codebase to leverage C++11 and later features for improved safety, performance, and maintainability (split from issue #42).
Scope
Systematically update C++ code to use modern language features while maintaining backward compatibility and ensuring no performance regressions.
Acceptance Criteria
- Use
autokeyword for type deduction where appropriate - Replace
NULLwithnullptrthroughout codebase - Implement range-based for loops where applicable
- Use uniform initialization syntax consistently
- Replace C-style casts with C++ style casts
- Implement move semantics where beneficial
- Use
overridekeyword for virtual functions - Add
finalkeyword where appropriate
Modernization Areas
1. Type Deduction with auto
Before:
std::vector<std::string>::iterator it = vec.begin();
std::map<int, std::string>::const_iterator cit = map.find(key);After:
auto it = vec.begin();
auto cit = map.find(key);Guidelines:
- Use
autowhen type is obvious from context - Avoid
autowhen it makes code less readable - Use
auto*for pointer types when needed for clarity
2. Null Pointer Modernization
Before:
if (ptr \!= NULL) {
// use ptr
}
char* p = NULL;After:
if (ptr \!= nullptr) {
// use ptr
}
char* p = nullptr;3. Range-Based For Loops
Before:
for (std::vector<int>::iterator it = vec.begin(); it \!= vec.end(); ++it) {
process(*it);
}After:
for (const auto& item : vec) {
process(item);
}4. Uniform Initialization
Before:
std::vector<int> vec(10, 0);
MyClass obj = MyClass();After:
std::vector<int> vec{10, 0}; // Be careful: this creates {10, 0}, not 10 zeros
std::vector<int> vec(10, 0); // Keep this for 10 zeros
MyClass obj{};5. C++ Style Casts
Before:
int* ptr = (int*)malloc(sizeof(int));
Base* base = (Base*)derived;
const int* cptr = (const int*)ptr;After:
int* ptr = static_cast<int*>(malloc(sizeof(int)));
Base* base = static_cast<Base*>(derived);
const int* cptr = const_cast<const int*>(ptr);6. Virtual Function Improvements
Before:
class Derived : public Base {
public:
virtual void func() { /* implementation */ }
virtual ~Derived() { }
};After:
class Derived : public Base {
public:
void func() override { /* implementation */ }
~Derived() override = default;
};7. Move Semantics (where beneficial)
Before:
class Resource {
char* data;
public:
Resource(const Resource& other) {
// expensive copy
}
};After:
class Resource {
std::unique_ptr<char[]> data;
public:
Resource(Resource&& other) noexcept = default;
Resource& operator=(Resource&& other) noexcept = default;
};Implementation Strategy
Phase 1: Safe Mechanical Changes
- Replace
NULLwithnullptr - Add
overridekeyword to virtual functions - Replace obvious C-style casts with C++ casts
- Remove deprecated
registerkeywords
Phase 2: Type System Improvements
- Introduce
autoin obvious cases - Use uniform initialization for new code
- Add range-based for loops where beneficial
- Use
finalkeyword for classes not meant to be inherited
Phase 3: Advanced Features (Careful Assessment Required)
- Evaluate move semantics opportunities
- Consider
constexprfor compile-time computations - Use
= defaultand= deletefor special members - Consider
noexceptspecifications
Priority Locations
High Priority Files
tol/bbasic/tol_bfsmem.h- Removeregisterkeywords- Core header files - Apply
nullptrand modern casts - Main algorithm files - Consider
autoand range-based loops
Medium Priority Files
- Grammar and parser files - Modernize where safe
- Type implementation files - Consider move semantics
- Utility classes - Add
overrideand modern patterns
Testing Strategy
# Comprehensive testing after each modernization phase
make clean
cmake .. -DCMAKE_CXX_STANDARD=11 -DCMAKE_BUILD_TYPE=Debug
make -j$(nproc)
make test
# Test with different C++ standards
cmake .. -DCMAKE_CXX_STANDARD=14
cmake .. -DCMAKE_CXX_STANDARD=17
# Performance regression testing
time make test # Before modernization
time make test # After modernization
# Memory usage comparison
valgrind --tool=massif ./build/bin/tolcon --versionCompiler Compatibility
Ensure changes work with:
- GCC 7+ (full C++14 support)
- Clang 6+ (full C++14 support)
- MSVC 2017+ (full C++14 support)
Related Issues
- Parent issue: Address C++ code quality and modernization issues #42 (Address C++ code quality and modernization issues)
- Prerequisite: Fix all compiler warnings with -Wall -Wextra #86 (Fix compiler warnings) - some warnings may be addressed by modernization
- Related: Modernize pending operator mechanism with std::vector #46 (Modernize pending operator mechanism)
Success Metrics
- Code compiles cleanly with C++11/14/17 standards
- No performance regression in benchmarks
- Improved code readability and maintainability
- Static analysis tools report fewer issues
- Modern C++ features used appropriately and consistently
Guidelines for Contributors
- Modernize incrementally, not all at once
- Prefer readability over showing off modern features
- Always test changes thoroughly
- Document any performance implications
- Consider maintenance burden of new patterns