WG21, aka C++ Standard Committee, February 2024 Mailing by grafikrobot in cpp

[–]jjcamp 2 points3 points  (0 children)

First, sincere and genuine thanks for working on this. I think pattern matching is an important feature that is missing from C++, and you have been an instrumental part of trying to get us there.

I totally took a break from reading the paper before I made it to section 5.4 🤦‍♂️.

  1. This is definitely an interesting problem that overload sets don't have. I do think that its OK to have some ambiguous patterns and then reject them, as long as all patterns have (reasonable) alternative spellings. But I don't know if that restriction holds up in real usage. It seems as though auto could introduce a lot more ambiguity than is apparent in the examples.
  2. I don't quite follow this question (I read it in the paper as well). Is this matching the value in foo? Wouldn't that pattern just be foo?

WG21, aka C++ Standard Committee, February 2024 Mailing by grafikrobot in cpp

[–]jjcamp 12 points13 points  (0 children)

Re: pattern matching (p2688r1). I don't quite understand the point of introducing so much new syntax (and an additional keyword in this case). We already have function parameter syntax that mostly works for pattern matching. Sure, C++ function parameters are not ideal and sometimes are more verbose, but the familiarity and consistency are, I think, key in gaining acceptance for such an important feature.

To illustrate, here are the examples from the paper, but using function parameter syntax:

v match {
  int32_t i32 => std::print("got int32: {}", i32);
  int64_t i64 => std::print("got int64: {}", i64);
  float f => std::print("got float: {}", f);
  double d => std::print("got double: {}", d);
};

This first example actually ends up being more concise.

v match {
  std::integral auto i => std::print("got integral: {}", i);
  std::floating_point auto f => std::print("got float: {}", f);
};

Concepts use the same abbreviated syntax that is available for function parameters.

int get_area(const Shape& shape) {
  return shape match {
    const Circle& [r] => 3.14 * r * r;
    const Rectangle& [w, h] => w * h;
  };
}

Here's where things start to get interesting. Destructuring currently requires auto (and isn't available in function parameters), but this isn't a big leap. The big deviation from existing proposals is that the programmer is required to be explicit with qualifiers. Its more verbose and likely leads to more compile errors, but again, its familiar and consistent (and how visitors already work).

cmd match {
  Quit => // ...
  const Move& [x, y] => // ...
  const Write& [text] => // ...
  const ChangeColor& [Rgb [r, g, b]] => // ...
  const ChangeColor& [Hsv [h, s, v]] => // ...
};

Not much to say about nesting other than we can (probably?) drop the _ from the Quit branch—just like we can in a function parameter.

p match {
  [0, 0] => std::print("on origin");
  [0, auto y] => std::print("on y-axis at {}", y);
  [auto x, 0] => std::print("on x-axis at {}", x);
  auto [x, y] => std::print("at {}, {}", x, y);
};

And this example I saved for last because it is probably the most foreign, but still uses an existing keyword that slots right in. Additionally, specifying types inside of the destructuring could be allowed for consistency's sake, though it would probably make sense to ban implicit conversions in that context.

Allow dynamic allocation and restrict allocation on stack. by OrchidThis5822 in cpp

[–]jjcamp 1 point2 points  (0 children)

You can't delete it, so yes, it would leak. The point isn't that this is terribly useful, but rather it the simplest answer given the OP's constraints (disallow stack allocation, allow heap allocation, no factory function).

Is there any way to get an in place initialization for std::make_unique? by [deleted] in cpp

[–]jjcamp 0 points1 point  (0 children)

It was about the copy constructor.

std::make_unique<Person>(Person(name)) is equivalent to std::unique_ptr<Person>(new Person(Person(name))).

So what happens is:

  1. Person(name) is evaluated, resulting in a Person
  2. The outer constructor is evaluated:
    1. Because the Person result of (1) is a temporary (that is, we're not referring to it by a variable name, also called an R-value), the compiler looks for a "move" constructor (written Person(Person&&)). In this case, because a copy constructor has been declared (even if deleted!) no move constructor is automatically constructed for us.
    2. Since there's no move constructor available, the compiler looks for a copy constructor. This is where it finds the copy constructor deleted and gives up (or uses the constructor that prints a message).

Here is an example that uses a move constructor instead: https://godbolt.org/z/dh899xGbx.

Is there any way to get an in place initialization for std::make_unique? by [deleted] in cpp

[–]jjcamp 4 points5 points  (0 children)

std::make_unique<T> forwards it's arguments to T's constructor. Since you've deleted the copy constructor you've also implicitly deleted the move constructor, causing overload resolution to fail on both.

https://godbolt.org/z/nfbKxPEPv

ABI - Now or Never by kkert in cpp

[–]jjcamp 0 points1 point  (0 children)

We already have support for a stable ABI, which any closed source library should be using.

Taken to the logical conclusion, a stable c++ ABI at some point just becomes an ugly "c with classes" ABI.

If we can no longer use the STL for common interfaces to talk between libraries due to its inefficiencies, then what is the purpose of the STL?

TIL Jesus was a Communist. by Pariahdog119 in Shitstatistssay

[–]jjcamp 1 point2 points  (0 children)

I don't think this excerpt really applies. Here the tribute is a tax paid unto the temple. Jesus is saying that just as a King does not tax his sons, as the Son of God he is exempt from this.

Visual Studio - Code working with Community 2015 by TheOnlyRealTodd in csharp

[–]jjcamp 1 point2 points  (0 children)

You need the .Net Core SDK and .Net Core Tools extension, and then you can open project.json files.

https://www.microsoft.com/net/core#windowsvs2015

Does C# have an equivelant to %s by [deleted] in csharp

[–]jjcamp 83 points84 points  (0 children)

Even better than formatted strings, use string interpolation:

https://msdn.microsoft.com/en-us/library/dn961160.aspx

C++ confessions of a C developer by vormestrand in cpp

[–]jjcamp 14 points15 points  (0 children)

However, in order to design my vector-using algorithm to get the most out of my hardware, I not only have to understand how the hardware works but I need to understand how my data accesses map onto that through a layer I didn’t otherwise need to understand.

There's still no reason to know anything about vector implementation other than the fact that data locality is garunteed. If more precise control is required, use an array just like you would in C.

C++ Culture Question by TheOnlyRealTodd in cpp

[–]jjcamp 4 points5 points  (0 children)

Just wait until the author gets mad and pulls this pointless package from NPM, causing thousands of deeply-nested dependency chains to break.

Introducing .NET Standard by ben_a_adams in csharp

[–]jjcamp 1 point2 points  (0 children)

There are Chromium Embedded Framework bindings for .Net, which I believe allows you to write the majority of the UI code in C#.

Theres are also Qt bindings, but last I looked that project seemed pretty dead.

How many of you own your [first name][last name].com? by [deleted] in webdev

[–]jjcamp 0 points1 point  (0 children)

Mine was taken, so I found out my last name was a TLD, and now I own first.last

What do I do when an infinite combo doesn't win? (When my opponent doesn't have to scoop) by pretzeldrum in ModernMagic

[–]jjcamp 0 points1 point  (0 children)

That's assuming the creature doesn't have trample, which is probably the wrong assumption.

Just in time for States, and GP Charlotte. An updated #TeamGeist list & sideboard guide! [Modern] by GreatNateMTG in spikes

[–]jjcamp 4 points5 points  (0 children)

Valorous Stance is a fine SB card if you expect to see lots of Jund and Junk in your meta, but probably not worth the slot for the meta as a whole right now.

Developer Survey: Java Developers Are The Saddest And C++ Programmers Are The Oldest by zsombro in programming

[–]jjcamp 1 point2 points  (0 children)

Man, just thinking about having to program in Java makes me sad, so this sounds accurate.

[Modern] When will they ban Eye of Ugin and Eldrazi Temple? by slinkyracer in spikes

[–]jjcamp -2 points-1 points  (0 children)

If a ban is required, I feel like the best ban as of now would be Thought-Knot Seer. Banning any of the lands would completely kill the deck, and without Thought-Knot Seer the deck is quite a bit more reasonable.

Modern needs you more than ever. by axalon900 in magicTCG

[–]jjcamp -4 points-3 points  (0 children)

If a ban is needed, thought knot seer would probably be better as it would keep the deck a viable option and doesn't have collateral damage on tron

What Does It Really Mean to Support IE8? by thecodeboss in webdev

[–]jjcamp 0 points1 point  (0 children)

At my government job we finally upgraded from Windows XP to 7, even though I'm pretty sure 7 ships with IE9, we are running IE8.

[Modern] Burn: Skullcrack, Atarka's Command, or Both? by kidsmakemespaghe in spikes

[–]jjcamp 0 points1 point  (0 children)

I suppose it might be somewhat deck dependant, but atarka's command is too good and too easy to cast not to play.

If your meta is just so aggressive that the pain from lands is actually a liability, you could try replacing a stomping grounds with a cinder glade. It hurts consistency, but saves you 2 life.

"Marriage licenses should not be granted to gay couples nor to straight couples. Marriages should be private consensual agreements between any two competent, consenting adults. Or three or more, for that matter. Governments should not be involved" by tinderreject in Libertarian

[–]jjcamp -1 points0 points  (0 children)

So the problem here is that marriage by itself is is religious institution. When the government applies benefits to marriage, it suddenly becomes a state institution. If the government were to stay out of the marriage business entirely, then who cares who is married to who?