- GeneralZod
- May 28, 2003
-
Kneel before Zod!
-
Grimey Drawer
|
I said they were identical except default public/private, he told me I was wrong, then I pulled out the relevant section of the specification (which I keep on my iPad), and told him he was probably thinking of POD types, but that classes could also be POD types, and nothing stopped a struct from not being a POD.
Did he tell you "the answer", in the end?
|
#
¿
Jun 21, 2016 08:12
|
|
- Adbot
-
ADBOT LOVES YOU
|
|
#
¿
May 10, 2024 18:39
|
|
- GeneralZod
- May 28, 2003
-
Kneel before Zod!
-
Grimey Drawer
|
I know C++ pretty well, but would struggle with that question, assuming it means "features that are in C++11 and not in prior releases".
Maybe I'd go for:
- The introduction of std::bind, which was almost wholly useless even in C++11 and is entirely useless in C++14;
- Personal taste - I don't like that std::thread begins executing on construction (edit: ah - apparently this might be a necessity on some platforms);
- The standardisation of the clunkier e.g std::enable_if<T>::type rather than C++14's less clunky e.g. std::enable_if_t<T>;
- Making constexpr methods implicitly const (rescinded in C++14).
GeneralZod fucked around with this message at 14:14 on Aug 16, 2016
|
#
¿
Aug 16, 2016 14:00
|
|
- GeneralZod
- May 28, 2003
-
Kneel before Zod!
-
Grimey Drawer
|
Seems to work with recent clang and gcc:
code:#include <type_traits>
#define class struct // Comment me out for compilability!
class A
{
static int f()
{
return 0;
};
};
template <typename T>
class B
{
public:
template <typename U, typename = decltype(U::f())>
static void g(U u);
static int g(...);
typedef decltype(g(std::declval<T>())) bloo;
};
int main()
{
B<A>::bloo x;
}
Maybe using type traits is cheating, but here's another one anyway:
code:#include <type_traits>
#define class struct // Comment me out for compilability!
class A
{
int i;
private:
int j;
};
template <typename T>
class B
{
};
template <>
class B<std::false_type>;
int main()
{
B<typename std::is_pod<A>::type> b;
}
GeneralZod fucked around with this message at 20:40 on Aug 23, 2016
|
#
¿
Aug 23, 2016 19:44
|
|
- GeneralZod
- May 28, 2003
-
Kneel before Zod!
-
Grimey Drawer
|
There are probably other examples, but try:
code:#include <iostream>
using namespace std;
#define ADD(x, y) x + y
template <typename T>
T add(const T& x, const T& y)
{
return x + y;
}
int main()
{
// The fact that I'm having to use printf instead of cout is bug #1 :p
printf("Normal add %d Macro ADD: %d\n", add(3 & 3, 4), ADD(3 & 3, 4));
printf("Normal add %d Macro ADD: %d\n", add(3, 5 & 3), ADD(3, 5 & 3));
printf("Normal add %d Macro ADD: %d\n", 5 * add(1, 2), 5 * ADD(1, 2));
}
edit:
For further fun, try:
code:#include <iostream>
using namespace std;
#define ADD(x, y) x + y
template <typename T, typename U>
class TwoTemplateTypes
{
public:
const static int value = 1;
};
template<typename T, typename U>
const int TwoTemplateTypes<T, U>::value;
template <typename T>
T add(const T& x, const T& y)
{
return x + y;
}
int main()
{
printf("Normal add %d Macro ADD: %d\n", add(TwoTemplateTypes<int, int>::value, 2),
ADD(TwoTemplateTypes<int, int>::value, 2)
);
}
GeneralZod fucked around with this message at 13:37 on Aug 24, 2016
|
#
¿
Aug 24, 2016 13:18
|
|