features which I would like to see in c++

Some c++ features I have looked for, but do not exist.

  • a std::min or compare which works for differently signed or sized arguments
  • an iteratorrange, which takes a pair of iterators
  • a way to test for the existence of a type in std::enable_if
  • initialize a subclass field before a baseclass
  • auto on class members
  • nested structured binding
  • automatic context deduction for switch

a std::min which works for signed + unsinged args.

Comparison and std::min, std::max such that I will not get compiler warnings telling me that unsigned and signed cannot be compared.

see: /Users/itsme/myprj/experiments/c++/fixed_min_max_less.cpp

a iterator_range constructor which takes a pair of iterators:

iterator_range(first, last)

std::enable_if conditionally on the existence of a type

std::enable_if<std::type_exists<V::membertype>>

allow to init member in derived class before base class init.

class Derived : public Base {
    std::vector<int> data;
    Derived()
        : data(5), Base(data)
    {
    }
};

auto class members

std::shared_ptr<int> somefunction();

class Tst {
    auto member;  // --> automatically detects 'shared_ptr<int>'
    Tst()
    {
        member = somefunction();
    }
};

emplace argument deduction

std::map<int, std::tuple<int,int>> m;
m.emplace(key, {1, 2});

nested binding

auto [a, [b, c] ] = x;

automatic context deduction for switch

namespace::classname::enumtype value;

switch(value)
{
    case CASE1: ...
    case CASE2: ...
}

instead of having to write

case namespace::classname::CASE1:

local context per case label

Now for many c++ constructs i have to wrap my ‘case’ code in braces, to avoid initialization issues.

why do i need the explicitly specify the basetype here

template<typename T>
class MyClass : public Base<T> {
    void foo() { Base<T>::_member->bar(); }
};

why does ^ have lower precedence than ==?

Now i have to type: (a^b) == 0 instead of a^b == 0, which actually means: a^(b==0)

can i have a byte string?

 b"test"

which has type const uint8_t*

make it easier to construct a byte-vector from a const string.

can declarations in the top level scope be order independent?

  • currently you can declare things in an order indepdent way inside classes, but not outside of them.