summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2023-06-20 16:32:32 +0200
committerTyge Løvset <[email protected]>2023-06-20 16:32:32 +0200
commit3fed66750bed9c82a8bb12fd86b963d2f5ec0eb5 (patch)
tree4a7c1d3c8a3774915a32f1d5e55846d89ae2c216 /include
parentde4f8fa86f141dfeab15f5576029910474f56fa1 (diff)
downloadSTC-modified-3fed66750bed9c82a8bb12fd86b963d2f5ec0eb5.tar.gz
STC-modified-3fed66750bed9c82a8bb12fd86b963d2f5ec0eb5.zip
Renamed `i_more` => `i_retain` (avoids undef of template parameters on next STC container inclusion).
Diffstat (limited to 'include')
-rw-r--r--include/stc/algo/sort.h23
-rw-r--r--include/stc/cdeq.h6
-rw-r--r--include/stc/priv/template2.h4
3 files changed, 26 insertions, 7 deletions
diff --git a/include/stc/algo/sort.h b/include/stc/algo/sort.h
index 291d90a6..002e6499 100644
--- a/include/stc/algo/sort.h
+++ b/include/stc/algo/sort.h
@@ -26,7 +26,7 @@ template params:
#define i_less - less function. default: *x < *y
#define i_type name - define {{name}}_sort_n(), else {{i_val}}array_sort_n().
-// test:
+// ex1:
#include <stdio.h>
#define i_val int
#include <stc/algo/sort.h>
@@ -34,12 +34,31 @@ template params:
int main() {
int nums[] = {23, 321, 5434, 25, 245, 1, 654, 33, 543, 21};
- intarray_sort_n(nums, c_arraylen(arr));
+ intarray_sort_n(nums, c_arraylen(nums));
for (int i = 0; i < c_arraylen(nums); i++)
printf(" %d", nums[i]);
puts("");
}
+
+// ex2:
+#define i_val int
+#define i_type IDeq
+#define i_retain // retain input template params to be reused by sort.h
+#include <stc/cdeq.h>
+#include <stc/algo/sort.h>
+
+int main() {
+ IDeq nums = c_init(IDeq, {5434, 25, 245, 1, 654, 33, 543, 21});
+ IDeq_push_front(&nums, 23);
+ IDeq_push_front(&nums, 321);
+
+ IDeq_sort_n(&nums, IDeq_size(&nums));
+
+ c_foreach (i, IDeq, nums)
+ printf(" %d", *i.ref);
+ IDeq_drop(&nums);
+}
*/
#include "../ccommon.h"
diff --git a/include/stc/cdeq.h b/include/stc/cdeq.h
index 0eac5a1d..06dfdb82 100644
--- a/include/stc/cdeq.h
+++ b/include/stc/cdeq.h
@@ -23,11 +23,11 @@
#define _i_prefix cdeq_
#define _pop _pop_front
#define _pull _pull_front
-#ifdef i_more
+#ifdef i_retain
#include "cqueue.h"
- #define i_more
+ #define i_retain
#else
- #define i_more
+ #define i_retain
#include "cqueue.h"
#endif
#undef _pop
diff --git a/include/stc/priv/template2.h b/include/stc/priv/template2.h
index 4604e610..47b82937 100644
--- a/include/stc/priv/template2.h
+++ b/include/stc/priv/template2.h
@@ -20,8 +20,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-#ifdef i_more
-#undef i_more
+#ifdef i_retain
+#undef i_retain
#else
#undef i_type
#undef i_tag