Skip to content

Commit

Permalink
work on c++ -std=c++98 compat WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
rurban committed Feb 20, 2024
1 parent cfed9b0 commit 5396a8f
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 45 deletions.
34 changes: 31 additions & 3 deletions tests/func/digi.hh
Original file line number Diff line number Diff line change
Expand Up @@ -74,23 +74,40 @@ digi_hash(digi* a)
return (size_t)int_hash_func(*a->value);
}

#if __cplusplus <= 199711
# define nullptr NULL
#endif

struct DIGI
{
int* value;
#if __cplusplus > 199711
DIGI(int _value): value { new int {_value} }
{
}
DIGI(): DIGI(0)
{
}
~DIGI()
DIGI(const DIGI& a): DIGI()
{
delete value;
*value = a.value ? *a.value : 0;
}
DIGI(const DIGI& a): DIGI()
#else
DIGI(int _value)
{
value = new int;
*value = _value;
}
DIGI(const DIGI& a)
{
value = new int;
*value = a.value ? *a.value : 0;
}
#endif
~DIGI()
{
delete value;
}
DIGI& operator=(const DIGI& a)
{
delete value;
Expand All @@ -111,6 +128,11 @@ struct DIGI
value = a.value;
a.value = nullptr;
}
#else
DIGI(DIGI& a)
{
*value = a.value ? *a.value : 0;
}
#endif
bool operator<(const DIGI& a) const
{
Expand Down Expand Up @@ -216,4 +238,10 @@ DIGI_bintrans (const DIGI& d1, const DIGI& d2)
return DIGI{*d1.value ^ *d2.value};
}

#if __cplusplus <= 199711
# define DIGI(n) DIGI(n)
#else
# define DIGI(n) DIGI{n}
#endif

#endif
Loading

0 comments on commit 5396a8f

Please sign in to comment.