Skip to content

Commit e12e04a

Browse files
committed
Even friendlier conftab::add thanks to non-deducible template parameters
Now, no casts at all should be needed. See the Stack Overflow link in weak_template.h for details. This'll probably be useful elsewhere too.
1 parent bcbf4b6 commit e12e04a

File tree

5 files changed

+17
-7
lines changed

5 files changed

+17
-7
lines changed

async/Makefile.am

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ parseopt.h qhash.h refcnt.h rxx.h serial.h stllike.h str.h \
2929
suio++.h sysconf.h union.h vatmpl.h vec.h rwfd.h litetime.h \
3030
corebench.h qtailq.h sfs_select.h rclist.h dynenum.h \
3131
rctailq.h rctree.h sfs_bundle.h alog2.h sfs_profiler.h wide_str.h \
32-
sfs_const.h
32+
sfs_const.h weak_template.h
3333

3434
#
3535
# begin sfslite changes

async/parseopt.h

+8-6
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "str.h"
3030
#include "ihash.h"
3131
#include "amisc.h"
32+
#include "weak_template.h"
3233

3334
class parseargs {
3435

@@ -262,13 +263,14 @@ class conftab {
262263
bool run (const str &file, u_int opts = 0, int fd = -1,
263264
status_t *sp = NULL);
264265

265-
template<class P, class D>
266-
conftab &add (const str &nm, P *dp, D lb, D ub)
267-
{ return insert (New conftab_int<P> (nm, dp, lb, ub)); }
266+
template<typename T>
267+
conftab &add (const str &nm, T *dp, WEAK_TMPL(T) lb, WEAK_TMPL(T) ub)
268+
{ return insert (New conftab_int<T> (nm, dp, lb, ub)); }
268269

269-
template<class P, class D>
270-
conftab &add (const str &nm, P *dp, D lb, D ub, D def)
271-
{ return insert (New conftab_int<P> (nm, dp, lb, ub, def)); }
270+
template<typename T>
271+
conftab &add (const str &nm, T *dp,
272+
WEAK_TMPL(T) lb, WEAK_TMPL(T) ub, WEAK_TMPL(T) def
273+
) { return insert (New conftab_int<T> (nm, dp, lb, ub, def)); }
272274

273275
template<class A>
274276
conftab &add (const str &nm, A a)

async/weak_template.h

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// -*-c++-*-
2+
#pragma once
3+
4+
// Thanks to Ben Voigt: http://stackoverflow.com/a/17433263/84745
5+
template <typename T> struct Identity { typedef T type; };
6+
#define WEAK_TMPL(T) typename Identity<T>::type

dist/freebsd-port/sfslite/pkg-plist

+1
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ include/sfslite-%%VERSION%%/%%TAG%%/rabin_fprint.h
135135
include/sfslite-%%VERSION%%/%%TAG%%/rabinpoly.h
136136
include/sfslite-%%VERSION%%/%%TAG%%/rexcommon.h
137137
include/sfslite-%%VERSION%%/%%TAG%%/sfssesscrypt.h
138+
include/sfslite-%%VERSION%%/%%TAG%%/weak_template.h
138139
lib/sfslite
139140
lib/sfslite-%%VERSION%%/acsfs.m4
140141
lib/sfslite-%%VERSION%%/%%TAG%%/aiod

dist/openbsd-port/pkg/PLIST

+1
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ include/sfslite-${REV}/shared/wmstr.h
125125
include/sfslite-${REV}/shared/xdr_suio.h
126126
include/sfslite-${REV}/shared/xdrmisc.h
127127
include/sfslite-${REV}/shared/xhinfo.h
128+
include/sfslite-${REV}/shared/weak_template.h
128129
lib/sfslite
129130
lib/sfslite-${REV}/acsfs.m4
130131
lib/sfslite-${REV}/shared/aiod

0 commit comments

Comments
 (0)