How do character array work as as template argument?Why can templates only be implemented in the header file?Where and why do I have to put the “template” and “typename” keywords?C++11 introduced a standardized memory model. What does it mean? And how is it going to affect C++ programming?why does the array decay to a pointer in a template functionSpecializing template member function to handle both std::string and char[] argumentsC++11 make_pair with specified template parameters doesn't compileHow to fill const std::array<size_t, N> with values based on functionList of values (of any types) as a template argumentImplementing is_constexpr_copiablec++ template instantiation works with int, long, etc. but not float, double, etc

Why should universal income be universal?

Why did the EU agree to delay the Brexit deadline?

Why is it that I can sometimes guess the next note?

Create all possible words using a set or letters

What is this called? Old film camera viewer?

Where does the bonus feat in the cleric starting package come from?

Is it safe to use olive oil to clean the ear wax?

Creepy dinosaur pc game identification

Pre-mixing cryogenic fuels and using only one fuel tank

How do you make your own symbol when Detexify fails?

What should you do when eye contact makes your subordinate uncomfortable?

Closed-form expression for certain product

I am looking for the correct translation of love for the phrase "in this sign love"

Fear of getting stuck on one programming language / technology that is not used in my country

Argument list too long when zipping large list of certain files in a folder

What does chmod -u do?

Offered money to buy a house, seller is asking for more to cover gap between their listing and mortgage owed

Why Shazam when there is already Superman?

Not using 's' for he/she/it

Multiplicative persistence

A social experiment. What is the worst that can happen?

Did arcade monitors have same pixel aspect ratio as TV sets?

Longest common substring in linear time

It grows, but water kills it



How do character array work as as template argument?


Why can templates only be implemented in the header file?Where and why do I have to put the “template” and “typename” keywords?C++11 introduced a standardized memory model. What does it mean? And how is it going to affect C++ programming?why does the array decay to a pointer in a template functionSpecializing template member function to handle both std::string and char[] argumentsC++11 make_pair with specified template parameters doesn't compileHow to fill const std::array<size_t, N> with values based on functionList of values (of any types) as a template argumentImplementing is_constexpr_copiablec++ template instantiation works with int, long, etc. but not float, double, etc













0















I have a bit of code that uses references to constexpr char arrays as template arguments. It turns out that new versions of MSVC fails to compile.



But it has no problems if I change the code to passing the array by value, which looks like this:



#include <cstddef>
#include <type_traits>
#include <utility>

template <char... Cs>
struct char_sequence ;

template <std::size_t N, const char (s)[N], typename T>
struct make_char_sequence_impl;

template <std::size_t N, const char (s)[N], std::size_t... i>
struct make_char_sequence_impl<N, s, std::index_sequence<i...>>
using type = char_sequence<s[i]...>;
;

template <std::size_t N, const char (Input)[N]>
using make_char_sequence =
typename make_char_sequence_impl<N, Input,
std::make_index_sequence<N - 1>>::type;

struct Delta
struct _alias_t
static constexpr const char _literal[] = "delta";
using _name_t = make_char_sequence<sizeof(_literal), _literal>;
;
;


According the cppreference:




Array and function types may be written in a template declaration, but they are automatically replaced by pointer to object and pointer to function as appropriate.




But if the parameter Input is a pointer in make_char_sequence, then how can it be passed to make_char_sequence_impl, which is expecting an array of specific size? Is that legal C++?










share|improve this question

















  • 1





    Nothing expects an array of a specific size, since as you quoted every array parameter is implicitly replaced by a pointer parameter (which has no size information). Now if you were to have only make_char_sequence_impl take a const char (&)[N], you'd see the error you expect with e.g. Clang.

    – Quentin
    2 days ago







  • 1





    @Quentin Oh dammit, struck by punctuation blindness again... Thanks for the explanation! So I can replace all the array stuff with pointers, which is much more readable anyway. Thanks again!

    – Rumburak
    2 days ago















0















I have a bit of code that uses references to constexpr char arrays as template arguments. It turns out that new versions of MSVC fails to compile.



But it has no problems if I change the code to passing the array by value, which looks like this:



#include <cstddef>
#include <type_traits>
#include <utility>

template <char... Cs>
struct char_sequence ;

template <std::size_t N, const char (s)[N], typename T>
struct make_char_sequence_impl;

template <std::size_t N, const char (s)[N], std::size_t... i>
struct make_char_sequence_impl<N, s, std::index_sequence<i...>>
using type = char_sequence<s[i]...>;
;

template <std::size_t N, const char (Input)[N]>
using make_char_sequence =
typename make_char_sequence_impl<N, Input,
std::make_index_sequence<N - 1>>::type;

struct Delta
struct _alias_t
static constexpr const char _literal[] = "delta";
using _name_t = make_char_sequence<sizeof(_literal), _literal>;
;
;


According the cppreference:




Array and function types may be written in a template declaration, but they are automatically replaced by pointer to object and pointer to function as appropriate.




But if the parameter Input is a pointer in make_char_sequence, then how can it be passed to make_char_sequence_impl, which is expecting an array of specific size? Is that legal C++?










share|improve this question

















  • 1





    Nothing expects an array of a specific size, since as you quoted every array parameter is implicitly replaced by a pointer parameter (which has no size information). Now if you were to have only make_char_sequence_impl take a const char (&)[N], you'd see the error you expect with e.g. Clang.

    – Quentin
    2 days ago







  • 1





    @Quentin Oh dammit, struck by punctuation blindness again... Thanks for the explanation! So I can replace all the array stuff with pointers, which is much more readable anyway. Thanks again!

    – Rumburak
    2 days ago













0












0








0








I have a bit of code that uses references to constexpr char arrays as template arguments. It turns out that new versions of MSVC fails to compile.



But it has no problems if I change the code to passing the array by value, which looks like this:



#include <cstddef>
#include <type_traits>
#include <utility>

template <char... Cs>
struct char_sequence ;

template <std::size_t N, const char (s)[N], typename T>
struct make_char_sequence_impl;

template <std::size_t N, const char (s)[N], std::size_t... i>
struct make_char_sequence_impl<N, s, std::index_sequence<i...>>
using type = char_sequence<s[i]...>;
;

template <std::size_t N, const char (Input)[N]>
using make_char_sequence =
typename make_char_sequence_impl<N, Input,
std::make_index_sequence<N - 1>>::type;

struct Delta
struct _alias_t
static constexpr const char _literal[] = "delta";
using _name_t = make_char_sequence<sizeof(_literal), _literal>;
;
;


According the cppreference:




Array and function types may be written in a template declaration, but they are automatically replaced by pointer to object and pointer to function as appropriate.




But if the parameter Input is a pointer in make_char_sequence, then how can it be passed to make_char_sequence_impl, which is expecting an array of specific size? Is that legal C++?










share|improve this question














I have a bit of code that uses references to constexpr char arrays as template arguments. It turns out that new versions of MSVC fails to compile.



But it has no problems if I change the code to passing the array by value, which looks like this:



#include <cstddef>
#include <type_traits>
#include <utility>

template <char... Cs>
struct char_sequence ;

template <std::size_t N, const char (s)[N], typename T>
struct make_char_sequence_impl;

template <std::size_t N, const char (s)[N], std::size_t... i>
struct make_char_sequence_impl<N, s, std::index_sequence<i...>>
using type = char_sequence<s[i]...>;
;

template <std::size_t N, const char (Input)[N]>
using make_char_sequence =
typename make_char_sequence_impl<N, Input,
std::make_index_sequence<N - 1>>::type;

struct Delta
struct _alias_t
static constexpr const char _literal[] = "delta";
using _name_t = make_char_sequence<sizeof(_literal), _literal>;
;
;


According the cppreference:




Array and function types may be written in a template declaration, but they are automatically replaced by pointer to object and pointer to function as appropriate.




But if the parameter Input is a pointer in make_char_sequence, then how can it be passed to make_char_sequence_impl, which is expecting an array of specific size? Is that legal C++?







templates c++14 language-lawyer






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 2 days ago









RumburakRumburak

1,855921




1,855921







  • 1





    Nothing expects an array of a specific size, since as you quoted every array parameter is implicitly replaced by a pointer parameter (which has no size information). Now if you were to have only make_char_sequence_impl take a const char (&)[N], you'd see the error you expect with e.g. Clang.

    – Quentin
    2 days ago







  • 1





    @Quentin Oh dammit, struck by punctuation blindness again... Thanks for the explanation! So I can replace all the array stuff with pointers, which is much more readable anyway. Thanks again!

    – Rumburak
    2 days ago












  • 1





    Nothing expects an array of a specific size, since as you quoted every array parameter is implicitly replaced by a pointer parameter (which has no size information). Now if you were to have only make_char_sequence_impl take a const char (&)[N], you'd see the error you expect with e.g. Clang.

    – Quentin
    2 days ago







  • 1





    @Quentin Oh dammit, struck by punctuation blindness again... Thanks for the explanation! So I can replace all the array stuff with pointers, which is much more readable anyway. Thanks again!

    – Rumburak
    2 days ago







1




1





Nothing expects an array of a specific size, since as you quoted every array parameter is implicitly replaced by a pointer parameter (which has no size information). Now if you were to have only make_char_sequence_impl take a const char (&)[N], you'd see the error you expect with e.g. Clang.

– Quentin
2 days ago






Nothing expects an array of a specific size, since as you quoted every array parameter is implicitly replaced by a pointer parameter (which has no size information). Now if you were to have only make_char_sequence_impl take a const char (&)[N], you'd see the error you expect with e.g. Clang.

– Quentin
2 days ago





1




1





@Quentin Oh dammit, struck by punctuation blindness again... Thanks for the explanation! So I can replace all the array stuff with pointers, which is much more readable anyway. Thanks again!

– Rumburak
2 days ago





@Quentin Oh dammit, struck by punctuation blindness again... Thanks for the explanation! So I can replace all the array stuff with pointers, which is much more readable anyway. Thanks again!

– Rumburak
2 days ago












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55281357%2fhow-do-character-array-work-as-as-template-argument%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55281357%2fhow-do-character-array-work-as-as-template-argument%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현