Thursday, 27 June 2019

C++: make_unique friendship

I've previously posted about adding a friendship to the shared_ptr base class to allow a public static function containing a "make_shared" to access private constructors....

Well, here's the partial move I've started to make in my own code bases to do the same with a unique_ptr.

#include <iostream>
#include <memory>

class Item;
using ItemPtr = std::unique_ptr<Item>;
class Item
    static ItemPtr Create()
        return std::make_unique<Item>();

    const int& Get() const
        return value;

    friend std::unique_ptr<Item> std::make_unique<Item>();

        : value(42)

    int value;

int main ()
auto i = Item::Crete();
std::cout << i->Get() << std::endl;

The secret sauce here is the friend, making the "make_unique" function a friend allows it to access the private constructor.

We could water-tight the "Item" class here by deleting the other constructors...

Item() = delete;
Item(const Item&) = delete;
Item(Item&&) = delete;
Item& operator=(const Item&) = delete;
Item& operator=(Item&&) = delete;

This way we stop any assignment to the type or construction except through the static "Create" function.

Nothing truly amazing here, but I challenge you all now to go add a parameter to the constructor... const int& incomingValue... perhaps and add it to the "Create" and try to set "value" to 100 instead of 42.

The template deduction for the type becomes a total mine-fiend, as the compiler wants to marry  up the "Type&& ..." underlying the parameters rather than treating it as a pure standard forward.

Saturday, 22 June 2019

Problem Neighbours - mY RanT FOr SanITy SaKE

Ooooommmmmmm.... I will remain calm..... Oooooommmmmm..... Neighbours eh... Everybody needs good neighbours, just a friendly wave each morning, helps to make a better day...

Yeah, not here.  So, we moved, just six months ago, on moving day the guy selling to us had what at the time seemed like a grand pantomime, he seemed to relish in stepping out the house for the last time and declaring the neighbours on one side to have been the worst neighbours he's ever had.

At the time we thought, Christ... and I even touched base with my solicitor whether this; whatever it was; should have been disclosed.  But it was not listed anywhere, querying there was no legal dispute it seemed to just be two folks not getting on.  Indeed, the neighbour in question popped around a day later to welcome us and gave us a potted plant, we exchanged christmas cards and thought nothing more of it.

Except, slowly over time, we started to see cars slowly encroaching on the drive...

Let me explain, we're in a block of three, a cul-de-sac off the main road, three houses in a row, with one tarmac area, the house to my left owned their whole front right out and we have an "easment" to cross it... Not a right of way per-say, but an easement such that anything related to the operation of my house I can cross their front... I then own the whole middle segment aligned with the neighbour to the left and my right hand wall... straight line.  Dead simple.

This line cuts right in front of the other neighbour, the problem neighbours, garage doors.

So, it's poor design, they're meant to store their cars in the garage, pull them out, shut the door and drive off... They're not meant to park on my drive in front of their garages.

However, these problem neighbours, before we even moved in decided to repurpose this double garage into a workshop, I had no idea of this when buying, none at all, the cars were not parked where they now were, but there seemed to be a status quo... So long as these parking neighbours didn't push it, we accepted them parking there and I left it with them as such when we spoke whilst I was out pottering and sorting the front garden.

Fast-forward two months, and suddenly they wanted to put a huge camper van there.  To their credit they came and asked if we minded, as rightly it would be a pain blocking the common access road to the whole close.  Fine, it parked there, but I said "this isn't a permanent thing, just a few days whilst you have these special visitors"... Fine, and it went, no problem.

You see, this cul-de-sac is on an incline, we're in the middle, nice neighbours to the left are down hill, problem neighbours are up hill... They say shit rolls down hill, but the problem with this incline is that their cars are at eye level as we sit in our nice new front room, literally there, no sky, no view just the underside rear of these cars which shouldn't be there... Which we're doing them a favour of letting them park there.

Fast forward again, and randomly this big blue VW van like people carrier appears.  This thing totally blots out what little view there was, just puft, no view... and it was a dark blue, so there was no reflected light either... It was a nice sunny day, but a miserable view.

Now, this turned out to be a visitor to problem neighbours, they stayed a few days.  I hark back to the other camper van and I you can see I gave an inch but suddenly it felt like a mile was taken.  So I waited until these visitors had gone, no-one wants to be embarrassed, and I quietly went to speak to the neighbours.

Well, never have I had such a drama.  The guy started to wail and grabbed his forehead "I don't need this stress, I saw all my mates shot in the middle east, I don't need this"... I was like, how the hell did I get from "can you refrain from parking that huge camper here" to combat casualties in the 1960's Lebanon or Sinai (he's not English BTW, this chap is Norwegian) plus he's hard of hearing, so I'm not sure he heard what I was saying at all with his own voice echoing in his ears.  It was a very simple request, just to make sure that the previous permission for the visiting camper, it was clear, didn't extend any further, that I didn't like it.

After all, it's my land... And this seems to be the crux of the problem, they want to use their garage in an unintended way, their solution then isn't to park somewhere else, it has been to park on my land.  Now, okay, I don't use that land and yes the width of it they have an easement over which they may pass, but it's a right of way, not a right of occupancy.

But the drama didn't stop there, this chap went to the other neighbours, the nice ones... Crying.

Now, he's in his mid-70's... and apparently sobbing that he's upset someone (we'll get back to that theme later).

My take away was he's got some form of PTSD, and I planned to speak to his wife when I saw her, she's always seemed more level headed, Poe faced and a bit stuck up, but sounded reasonable, and she's not hard of hearing and English so I thought there'd be no deafness nor language barrier.


She appeared about an hour later knocking on my door, and her words about the visiting camper were... "Do you know how much that cost?"...

Like I was meant to be impressed!... Conspicuous consumption does not flatter the beholder love.  It was a dirty great tin can on wheels with a white plastic roof (can you tell I'm not interested in cars?) and even if it was say a Lamborghini sat there, it'd still have been sat on my land, in my eye line and not either of their (the neighbours) car which we'd had allowed.

Her then immediate reaction was to turn on the other neighbours, the nice ones, who happened to have a caravan on their front that day... "What about that caravan?! You've not told them".

No, because firstly the caravan was on their drive, in their car port, it was not blocking nor on any part of my land at all.  Second the neighbour herself had said, "It'll not be there long, I can't stand it being there, its only here before we go away at the weekend"... Which was all fair enough.

Problem neighbour didn't like that though, she stomped off... I called after her "Sorry"  I wish I hadn't, I should have stuck to my guns.

But I spoke to my solicitor about this, he said "keep it a civil matter, the moment you involve me you'll have problems if you ever want to sell.  But send them a letter, explain what you don't like, what you will tolerate".

So I did, I explained my intention was not to upset him, I explained though that it's quite ugly, not our cup of tea, that they are over our boundary and we accepted their two cars only as a neighbourly favour.  I didn't want to be petty and just summarily ban them.... I kind of wish I had now.

I suggested, maybe if they convert half the garage back and put one in, at least swap them over so the larger car is further away from my window.  And if they ever wanted to talk to us please do.  That they can park their two cars, but not visitors and if ever they, or we, put the houses on the market the cars to move immediately.  As I didn't want this to be inherited as a problem down the line.

That letter was handed over a month ago... What's happened since has been subtle signed of rebellion, so they did swap the cars around so the larger darker one was further away from the windows.  But then they started to drop the other one back... Not pull it to the garage doors as they had done... Just a subtle "fuck you".

Then, they started to slowly drift the cars pulling up towards the property, rather than sticking; as they had for so many months; to the far fence.

And then the drama yesterday... and just now....

So, both our rabbits have had operations and one of them stopped breathing and went blue, the vet needed permissions signing to act, I gave verbal permission and went to go sort things out... I was so frantic.  I called my wife to come back from the dog walk she was on and we'd swap, she'd stay with the dogs and I'd drive to the vets.

The wife came in, and said "you can't get out"... There was a giant van parked there... Blocking my entire front.

Now, I immediately recognised this van, it's a battered old 1990's ambulance with a hand painted sign about being a mean green machine.  It was just sat there, it belongs to a guy at the top of the street who has two such monstrosities.

I got my shoes, grabbed my keys, and went to knock on the problem neighbours door... I knocked... And rang the bell, and knocked... Nothing... 3 minutes seems like an eternity... Five minutes and I can vaguely hear voices down their far side alley, so I call down "coo, it's me from next door can you move your van"... Laughter, more chatting... 6 minutes seem like a very long time, I rang the door bell.. Remember I know the guy is nearly deaf, these voices sound male, so I call again... "Hello, can you move your van"... Nothing.

My wife calls to me, "they're in the back garden, call over our fence".

So I pop down and get up and call over, there's the owner of the van say chatting with the wife (she must have a very manly voice for it to sound like that) anyway, I ask him to move it "can you move your van"...


"because I need to get out"

"Who needs to get out"

"I do"

"Alright, in a minute"

I'm getting mightily annoyed now....

"No, now, I need to go out now"  I don't want to say "cus my bunny is maybe dead" that's not macho enough, but this prick just gives me this fucking stare

"Who wants me to move?"

"I do, me"

"And who are you"

"Just move the van now"

He's grunting and grumbling but he steps into the conservatory on the back of next doors, and does the most stupid thing, he grabs his crotch with his left hand and makes the wanker sign at me with his right, like I can't see him... Clearly their opinion of me is that level, the owner of the house she sits there impassive, she doesn't say anything, she doesn't say "sorry" to me, or "please go move it" to this is a visitor to her house....

I see this gesture and I call "don't make that sign at me"

"Fuck off" he screams, literally, as he gets in his van "this is a right of way, fuck you"

"This is not a right of way, this is private property you are not delivering or doing anything other than block me in, this is my drive, my land, and if you make that gesture at me again you will regret it"

"Fuck you, I'll fucking knock you spark out"

"You will try, now move this shit heap off my drive"

"Fuck you, show some respect for your neighbours, how long have you lived here?!"

"Six months, and you have a whole empty road to park on, but park here blocking me in, you show some respect, now move it"

"I'll fucking knock you spark out talking to me like this, who do you think you are"

"The owner of this land, and you try and hit me you will regret it"

I don't think this floppy haired idiot has ever been stood up to before, he seemed quite willing to mouth, but had no trousers on, I meanwhile really, really wanted to break some part of his scrawny little know nothing body.

He finally moves, but I've not got my phone, so I turn around to get it and the vet is calling, I take the call.  Bunny lives, just she's blue but alive.

I quickly go speak to the neighbour, in the hope of pointing out this was exactly what was on that civil letter sent not a month before... her instant stance "it has nothing to do with me, Andy is having a hell of a bad time at the moment" and she's putting up her hands... I really don't care what kind of time he's having.  And a visitor to her house, blocking completely the neighbouring property, on a contentious issue they've already had a letter about and then said visitor being abusive and threatening the owner and person in the right.... Nothing to do with her.  Right, got your level.

I'm starting to see where this worst neighbour mantle awarded them comes from, because they are, they're awful passive aggressive people, stuck up and not a little spiteful.  I've told numerous visitors to park on the road, this guy as well should know that, he lives on the same street!  But oh no, "it's a right of way", his van was empty, he was in their back garden chatting... Fuck that, tired of it.

I left her there, went to the vets.

As I'm coming back from the vets I call through to the nice neighbours, after the pantomime of him going crying to them before I wanted to just nip any miss communication in the bud, not least as this abusive wally has two clapped out vans blocking both his drives to his wife parks his car on nice neighbours drive when they're away; which they are now.

Nice neighbour immediately said this Andy is an idiot, he's fallen out with multiple people over his time on the street.

As for the problem neighbours, she wouldn't be drawn on them, but admitted that this whole issue had come up with the people who sold this house to me, the moment they moved in these problem neighbours were take take take, push, push, push.

So, this morning, I'm actually again back from the vets, bunnies in their carriers on in each hand.  And the problem neighbour block, the deaf one, pulls up.  I wait a moment and say morning, and I say "That unpleasentness with Andy yesterday".

Before I can continue... "Its nothing to do with us".

"He was a visitor to your property, it is to do with you"

"It has nothing to do with us" and he lifted both arms palms towards me and motioned to bat me away like a fly.

I called after him "That's it now, I've tried to speak to you twice, clearly I can't speak to you, I shall not try again".

What else can you do with people like this?

I am very tempted right now to tell them to get the solicitor involved and just injunction them from parking on my land, they have a double garage use it.  And to reinforce legally that this easement is not a right of occupancy, and to clarify it's not a right of way.

So an easement is a permission that I have to give to let them cross my land, for the function and purposes of the running of their house, so deliveries and their own access to their border and garage front.

It's not a permission to park.

Now, on moving day the drama kicked off when the deaf problem guy did try to tell me the border was elsewhere from where it is, he tried to tell me it was dog legged off another wall and so he owned this piece of land his cars are over onto.  I immediately nipped that in the bud, and clearly they went back to review their own legals as he even verbally admitted "I am a long way over onto your land, are you sure you don't mind".... Stupidly I said, I didn't.

In hindsight, I wish I'd have said it annoys the shit out of me, because that's where we are now, that niggling annoying thing you can't yourself easily solve.  Legally they don't have a leg to stand on, they're on my land, on my terms, they've violated the civil request in a most uproarious fashion and then want to wash their hands of it.

If they'd say "I'm so sorry he spoke to you like that, he is in a bad place, I'll have a word with him" then that'd have been much better, pacify both parties, as you try to do, instead passive aggressive "nothing to do with us"... Like it's a sport, they're goading you on that little bit.

The ultimate step for me is to speak to my solicitor, give them a date to move the cars and my reclaim and affirm the land as mine.  That puts me in a difficult situation regarding selling down the line, we were not thinking of selling, only just getting here, but this situation is enough to put you off.

We shall see, but this is one of my rant posts, an insight into the passive aggressive or out and out yobbish behaviour of the British public.

Monday, 17 June 2019

C++ : "ignored-qualifiers" warnings are a bit wrong

It has been a while hasn't it... I'm very busy, sorry.... But here's an item, the const qualifier on return types in C++... So, I'm of the same mind as Scott Meyers that you should const everything you can whenever possible, and one place I always const is on return codes from functions where I don't want the result to be mutable, like this:

const bool OverTen(const int& p_Value)
return p_Value > 10;

I don't want the caller to this function to modify the result, that bool they get back, I want it to be constant, I want them to use that bool for that one purpose.

This compiled fine, until you compile with -Wextra, where you then get -Wignored-qualifies and the message:

warning: 'const' type qualifier on return rype has no effect

But I want it to have an effect, I want that to be immutable, it's a constant boolean.  It could be anything, a constant error code value, I don't want someone to fudge over an error by setting it to some other value!  I want it to be constant.

It not being constant allows crusty code like this:

auto test = OverTen(2);

if ( NefariousProgrammersBirthday() )
test = true;

if ( test )

I'm sure you can see where this is going.

but, but but, you're going to argue that I'm assigning to auto, I'm not using "const auto".  Well that's my point, I want the warning to tell the programmer that they're assigning my const return type to a non-const auto, that they should be using "const auto" and hence close this loop hole.

Instead the compiler warns you that your API, the return being const, has no effect.  It should have an effect, the return is constant and it should be hard to get rid of that constness.

For instance if one had to const_cast like so:

auto test = OverTen(2);
if ( NefariousProgrammersBirthday() )
test = const_cast<bool>(test);
test = true;

Well, that jumps out at you, as would

auto test = const_cast<bool>(OverTen(2));

or even

auto test = (bool)OverTen(2);

So, I would suggest that if a return type has const the auto becomes "const auto" immediately, attempts to change this are easy to spot.

And -Wignored-qualifiers should NOT report a warning on a const qualification of a return, because it is being used in the auto case, and then if it were being assigned to a mutable type:

bool test = OverTen(2);

Then you should truly get an ignored-qualifiers warning, because the const on the function result is being ignored.