Skip to content

Commit 73e979d

Browse files
Added NullPtrTable<FunPtrT> and NullPtrVector<FunPtrT> classes (yet unused)
1 parent f3535f1 commit 73e979d

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed

dpctl/tensor/libtensor/include/utils/type_dispatch.hpp

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,96 @@ template <typename T> struct GetTypeid
333333
}
334334
};
335335

336+
/*! @brief Class to generate vector of null function pointers */
337+
template <typename FunPtrT> struct NullPtrVector
338+
{
339+
340+
using iterator_category = std::forward_iterator_tag;
341+
using different_type = std::ptrdiff_t;
342+
using value_type = FunPtrT;
343+
using pointer = value_type *;
344+
using reference = value_type &;
345+
346+
NullPtrVector() : val(nullptr) {}
347+
348+
reference operator*()
349+
{
350+
return val;
351+
}
352+
353+
reference operator[](int)
354+
{
355+
return val;
356+
}
357+
358+
NullPtrVector<FunPtrT> &operator++()
359+
{
360+
return *this;
361+
}
362+
NullPtrVector<FunPtrT> operator++(int)
363+
{
364+
return *this;
365+
}
366+
367+
friend bool operator==(const NullPtrVector<FunPtrT> &a,
368+
const NullPtrVector<FunPtrT> &b)
369+
{
370+
return true;
371+
}
372+
friend bool operator!=(const NullPtrVector<FunPtrT> &a,
373+
const NullPtrVector<FunPtrT> &b)
374+
{
375+
return false;
376+
}
377+
378+
private:
379+
value_type val;
380+
};
381+
382+
/*! @brief Class to generate table of null function pointers */
383+
template <typename FunPtrT> struct NullPtrTable
384+
{
385+
using iterator_category = std::forward_iterator_tag;
386+
using different_type = std::ptrdiff_t;
387+
using value_type = NullPtrVector<FunPtrT>;
388+
using pointer = value_type *;
389+
using reference = value_type &;
390+
391+
NullPtrTable() : val() {}
392+
393+
reference operator*()
394+
{
395+
return val;
396+
}
397+
reference operator[](int)
398+
{
399+
return val;
400+
}
401+
402+
NullPtrTable<FunPtrT> &operator++()
403+
{
404+
return *this;
405+
}
406+
NullPtrTable<FunPtrT> operator++(int)
407+
{
408+
return *this;
409+
}
410+
411+
friend bool operator==(const NullPtrTable<FunPtrT> &a,
412+
const NullPtrTable<FunPtrT> &b)
413+
{
414+
return true;
415+
}
416+
friend bool operator!=(const NullPtrTable<FunPtrT> &a,
417+
const NullPtrTable<FunPtrT> &b)
418+
{
419+
return false;
420+
}
421+
422+
private:
423+
value_type val;
424+
};
425+
336426
} // namespace type_dispatch
337427

338428
} // namespace tensor

0 commit comments

Comments
 (0)