summaryrefslogtreecommitdiff
path: root/6p30.cpp
diff options
context:
space:
mode:
authorOskar <[email protected]>2024-09-12 12:28:48 +0200
committerOskar <[email protected]>2024-09-12 12:28:48 +0200
commit13c97461fde19829569dbe10f53322fef5909b83 (patch)
tree7f7f529c849c601184edc95b9a449e870e2854dc /6p30.cpp
parent70878e5c5b4552def51082829032780c536dc59d (diff)
more
Diffstat (limited to '6p30.cpp')
-rw-r--r--6p30.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/6p30.cpp b/6p30.cpp
new file mode 100644
index 0000000..064b56f
--- /dev/null
+++ b/6p30.cpp
@@ -0,0 +1,35 @@
+#include <iostream>
+
+/*
+ *
+ * 6.30
+ *
+ *
+ */
+
+/*
+bool str_subrange(const std::string &str1, const std::string &str2)
+{
+// same sizes: return normal equality test
+ if (str1.size() == str2.size())
+ return str1 == str2;
+ // ok: == returns bool
+ // find the size of the smaller string; conditional operator, see ยง 4.7 (p. 151)
+ auto size = (str1.size() < str2.size())
+ ? str1.size() : str2.size();
+
+ // look at each element up to the size of the smaller string
+ for (decltype(size) i = 0; i != size; ++i) {
+ if (str1[i] != str2[i])
+ return; // error #1: no return value; compiler should detect this error
+ }
+ // error #2: control might flow off the end of the function without a return
+ // the compiler might not detect this error
+}
+*/
+
+int main () {
+
+ // Tested both with clang++ and g++ and both detected the error
+ return 0;
+}