// example using checked_array.hpp // (c) 2006 David Manura, Licensed under the MIT license. #include "checked_array.hpp" #include using namespace std; template inline void debug(const S & s) { cout << s.c_str_const() << " " << s.length() << " " << s.maxlength() << endl; } char c[6] = "test"; int main() { bool b = false; char_array<10> s(b ? "test" : "test5678"); s.maxlength(9); //fix:improve interface? strcat_t(s, "z"); debug(s); // strcat_t(s, "2"); // fails: maxlength exceeds capacity strtruncate_t(s, 4); debug(s); char_array<6> s2(s); strcat_t(s2, "z"); debug(s); debug(s2); // char_array_ref<10> s3(c, false); // fails: capacity exceeds source char_array_ref<6> s3(c, false); debug(s3); strcat_t(s3, "a"); // strcat_t(s3, "b"); // fails: maxlength exceeds capacity cout << c << endl; return 0; }