Description:
Technical discussion of the C++ language. (Moderated)
|
|
|
Vector sizes and other missed optimizations
|
| |
This has been annoying me for a while:
...
template<typename T>
class Vec
{
public:
Vec(size_t len) : len_(len) { data_ = new T[len]; }
~Vec() { delete data_; }
Vec(const Vec &) = delete;
void operator = (const Vec &) = delete;
size_t size() const { return len_; }
T &operator [] (size_t pos) { return data_[pos]; }... more »
|
|
Design patterns exercises
|
| |
Hi group,
Possibly OT, but comp.software.patterns seems to be just a spam NG and
am exclusively interested in c++ at this time, so here goes
{ Not at all; your question is relevant to the C++ community -mod/we }
I wonder if you could recommend some books or some online resources
where I would find exercises for each of the specific design patterns.... more »
|
|
Dereferencing and returning by reference!
|
| |
Consider a small unit test case
struct A
{
virtual void func(){}
A& foo()
{
A *obj = reinterpret_cast<A*>(0xdeadbee f);
return *obj; //1
}
...
int main()
{
A obj = obj.foo();
...
At line 1 is it implementation defined/unspecified that the deference
would not happen as we are returning by reference and the program... more »
|
|
sequence of inheritance from virtual base class?
|
| |
I have a problem with the sequence of inheritance:
// header1.h
class Base {
public:
Base() {}
virtual ~Base() {}
virtual void foo() = 0;
};
// header2.h
#include "header1.h"
class Unrelated1 {};
class Unrelated2 {};
class Derived1 : public Base, public Unrelated1, public Unrelated2 {... more »
|
|
Why are in class initializers not allowed?
|
| |
In the C++ Standard - before C++11 - any attempt to initialize a
variable inside the body of a class would fail at compilation. I am
sure that there is / was a very good reason for this, but can't
understand why it is so.
I thought that maybe it was a restriction that was imposed due to some... more »
|
|
Immutable data structures - performance && thoughts
|
| |
Hi all,
I recently looked over how a C# library could implement an immutable
stack, and came up with this implementation in C++. I wonder here
mostly about the overhead of std::shared_pointer(and the missing of a
garbage collector that probably could help for this kinds of
structures)
namespace immutable... more »
|
|
compilers, endianness and padding
|
| |
I've been looking around and am just shocked that there still after so
many years, there doesn't seem to be any way of using the optimizer or
templating system in any consistent way across compilers to generate a
compile time endianness value. Does anyone know why the C++ committee
has steered clear of this?... more »
|
|
|