Can someone explain how this template syntax and use of decltype works? More specifically what t="" does.
template <typename t="">
void createVkBuffer(
T& vkData,
VkBuffer& buffer,
VkDeviceMemory& bufferMemory,
VkBufferUsageFlags usage)
Dude, if you wanna learn vulkan I strongly recommend you just use the raw C api and not some C++ wrapper. Eventually you, Go back to the C++ wrapper, but only AFTER you're comfortable with the vulkan API.
>decltype
Returns the type of the entity that you pass to it, you'll know when you'll need it when you'll find out it's either impossible to find out or too tedious to write the type of something. >what t="" does
Produces a compilation error, probably meant "template<typename t>". String literal template arguments are done in a different way, and are only possible since C++20.
It literally doesn't mean anything, have you tried compiling that code?
template <typename T=""> void x();
x.cpp:1:22: error: expected a type
template <typename T=""> void x();
^
x.cpp:1:22: error: expected ',' or '>' in template-parameter-list
String literals can't be directly passed as template arguments in general, although it is possible with a workaround.
First of all: language doesn't fucking matter. All that matters is what you can create, not what languages you can learn.
But yeah, there are better alternatives for C++ these days. Be warned that with C++ (or C) you'll be fucking around with build tools,scripts, and compiler flags way more than actually developing your app/library.
Learn golang,zig or rust. They all have modules AFAIK and have sane solutions for building your code.
>But yeah, there are better alternatives for C++ these days.
No there aren't. C and C++ are the peak of all programming languages.
https://i.imgur.com/ZBQ9re8.jpg
I'm learning C++. How was you C++ (hellish) journey?
Personally I had fun. Stop thinking of it as a chore and start having fun with it. Its actually a great language and you can do a lot of things with it.
>language evolving every 4 year is a problem too.
Not a cpp programmer but can't you download a linter or code analyser that'll ping you for not using the preferred choice for whichever version of CPP being used?
I started learning C++ many years ago and I didn't really know what to do, so I pulled up an Indian fellow on YouTube and copied his code letter by letter.
Then I started making my own crappy programs.
Then I made slightly more complicated stuff like a chess movegen.
Then some shit happened.
Then I started doing max difficulty programming challenges, from which I learnt the art of extreme optimization, among other things.
And only within the last year I've felt that I mastered the language.
It was pretty much my first language if you don't count minor dabbling with JS/Python back in the day.
C++ isn't really that hard, it's just a glorified C. It's harder to know what to do with it, there are a lot of little features that can twist your designs into a strange spaghetti of constructs because it allows you to bypass your own flaws like creating an ill thought out object interfaces and compositions. For example at work some colleagues may come up with some interesting classes but end up dynamic_cast-ing everywhere (this is not because of lack of virtual functions but wrong composition), making it more difficult to bend the code to your will later, and eventually refactoring keeps occuring due to this.
>How was you C++ (hellish) journey?
It was fine honestly, started at the age of 14 by just copy pasting others' code and it worked out just fine because I knew exactly what I wanted to get out at the end.
I've read C++ Primer Plus when I was in uni some 10 years ago. No idea how it holds up today.
>C++
>2k23
Give it a rest already holy shit. Learn plain C if needs be but not this meme abomination.
.t former C++ mainer of 5 years
Then, what langage more complex than Python should I learn?
The one with the best job prospects in your area of course. 'Learning' a lang for the sake of it gets you nothing.
Learned it on the job.
Shit’s easier to learn when you have an [good] existing code base to crib off of and actual tasks to do.
Easy until I got to auto const std::vector, shared ptr, unique ptr and other garbage they added for more bloat.
absolutely filtered
Learn C, use C++ for objects
Can someone explain how this template syntax and use of decltype works? More specifically what t="" does.
template <typename t="">
void createVkBuffer(
T& vkData,
VkBuffer& buffer,
VkDeviceMemory& bufferMemory,
VkBufferUsageFlags usage)
createVkBuffer<decltype(vkvertices)>(
vkVertices,
vkVertexBuffer,
vkVertexBufferMemory,
VK_BUFFER_USAGE_VERTEX_BUFFER_BIT
);
createVkBuffer<decltype(vkindices)>(
vkIndices,
vkIndexBuffer,
vkIndexBufferMemory,
VK_BUFFER_USAGE_INDEX_BUFFER_BIT
);
Dude, if you wanna learn vulkan I strongly recommend you just use the raw C api and not some C++ wrapper. Eventually you, Go back to the C++ wrapper, but only AFTER you're comfortable with the vulkan API.
I want to know the template typename syntax which doesn't show up anywhere on cppreference with empty quotes.
>decltype
Returns the type of the entity that you pass to it, you'll know when you'll need it when you'll find out it's either impossible to find out or too tedious to write the type of something.
>what t="" does
Produces a compilation error, probably meant "template<typename t>". String literal template arguments are done in a different way, and are only possible since C++20.
><typename t="">
Could be the ="" means any string literal will be converted to a type?
It literally doesn't mean anything, have you tried compiling that code?
template <typename T=""> void x();
x.cpp:1:22: error: expected a type
template <typename T=""> void x();
^
x.cpp:1:22: error: expected ',' or '>' in template-parameter-list
String literals can't be directly passed as template arguments in general, although it is possible with a workaround.
That's not valid code.
First of all: language doesn't fucking matter. All that matters is what you can create, not what languages you can learn.
But yeah, there are better alternatives for C++ these days. Be warned that with C++ (or C) you'll be fucking around with build tools,scripts, and compiler flags way more than actually developing your app/library.
Learn golang,zig or rust. They all have modules AFAIK and have sane solutions for building your code.
>But yeah, there are better alternatives for C++ these days.
No there aren't. C and C++ are the peak of all programming languages.
Personally I had fun. Stop thinking of it as a chore and start having fun with it. Its actually a great language and you can do a lot of things with it.
Not English native speaker, so C++ was hell specially without mentors, language evolving every 4 year is a problem too.
Not really, do what you know, don’t do what you don’t.
>t. filtered by C++14.
Yeah but you need to understand what has changed internally to understand new declarations.
You don’t. You don’t have to use a new code version just because it exists.
> t. Maintains code locked in various decades
>language evolving every 4 year is a problem too.
Not a cpp programmer but can't you download a linter or code analyser that'll ping you for not using the preferred choice for whichever version of CPP being used?
It's alright, I'm 10 years in. Forget about raw pointers, use const& everywhere, don't try to invent your own containers and it'll be fine.
If you're already familiar with C and Python, it shouldn't be too bad.
I started learning C++ many years ago and I didn't really know what to do, so I pulled up an Indian fellow on YouTube and copied his code letter by letter.
Then I started making my own crappy programs.
Then I made slightly more complicated stuff like a chess movegen.
Then some shit happened.
Then I started doing max difficulty programming challenges, from which I learnt the art of extreme optimization, among other things.
And only within the last year I've felt that I mastered the language.
It was pretty much my first language if you don't count minor dabbling with JS/Python back in the day.
C++ is easy what's difficult is building, linking and managing libraries. It's not like other languages where you don't need to think about it.
C++ isn't really that hard, it's just a glorified C. It's harder to know what to do with it, there are a lot of little features that can twist your designs into a strange spaghetti of constructs because it allows you to bypass your own flaws like creating an ill thought out object interfaces and compositions. For example at work some colleagues may come up with some interesting classes but end up dynamic_cast-ing everywhere (this is not because of lack of virtual functions but wrong composition), making it more difficult to bend the code to your will later, and eventually refactoring keeps occuring due to this.
>How was you C++ (hellish) journey?
It was fine honestly, started at the age of 14 by just copy pasting others' code and it worked out just fine because I knew exactly what I wanted to get out at the end.