# Array to pointer class template argument deduction works for template guide, but not for non template version, is that correct or bug?

• A+
Category：Languages

I have class template with single type param and `const char*` type full specialization, simplified example below:

``template <typename T> struct PrettyPrint {     PrettyPrint(const T& value) : value(value) {}     const T& value;     friend std::ostream& operator << (std::ostream& os, const PrettyPrint& pp) {         return os << "(" << pp.value << ")";     } }; template <> struct PrettyPrint<const char*> {     PrettyPrint(const char* value) : value(value) {}     const char* value;     friend std::ostream& operator << (std::ostream& os, const PrettyPrint& pp) {         return os << "/"" << pp.value << "/"";     } }; ``

In short - to print char strings like `"abc"` and all other values like `(123)` (`""` vs `()`)

So, I added, as a replacement of additional partial specialization for all `char[N]` types a deduction guide:

``template <std::size_t N> PrettyPrint(char(&)[N]) -> PrettyPrint<const char*>; //deduction guide ``

Unfortunately it does not work:

`` std::cout << PrettyPrint(7) << PrettyPrint("aaa") << PrettyPrint((const char*)"bbb"); ``

(7)(aaa)"bbb"

Expected output:

(7)"aaa""bbb"

But, surprisingly, this works:

``template <typename T, std::size_t N> PrettyPrinter(T(&)[N]) -> PrettyPrinter<const T*>; //deduction guide   std::cout << PrettyPrint(7) << PrettyPrint("aaa") << PrettyPrint((const char*)"bbb"); ``

(7)"aaa""bbb"

So the questions:

1. Is that correct (then why) or this is a bug in compilers (tested with gcc/clang - newest versions)
2. If that is correct - then how to limit this template deduction guide to `char` only?

This is expected. A string literal has type `const char[N]`. Note the `const`. A const value cannot bind to a non-const reference, so your deduction guide is effectively not chosen and the primary template gets instantiated instead.

``template <std::size_t N> PrettyPrint(const char(&)[N]) -> PrettyPrint<const char*>; ``

Your second deduction guide works because here, `T` is deduced to be `const char`, which is perfectly fine.
{"ft_lang_label":"__label__en","ft_lang_prob":0.5814235,"math_prob":0.8159796,"size":1892,"snap":"2019-43-2019-47","text_gpt3_token_len":472,"char_repetition_ratio":0.19862288,"word_repetition_ratio":0.10869565,"special_character_ratio":0.28911206,"punctuation_ratio":0.16816817,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9568163,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2019-11-15T23:19:40Z\",\"WARC-Record-ID\":\"<urn:uuid:08cf652f-6306-4ca8-ba08-644c96dffc69>\",\"Content-Length\":\"35222\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:fb17ee5e-b39a-4c32-83a7-9c292cdf2f8d>\",\"WARC-Concurrent-To\":\"<urn:uuid:4eaceebe-f8e8-44b4-a1c3-e6ead1c35028>\",\"WARC-IP-Address\":\"45.56.93.102\",\"WARC-Target-URI\":\"https://www.developerfaqs.com/1059/array-to-pointer-class-template-argument-deduction-works-for-template-guide-but-not-for-non-template-version-is-that-correct-or-bug\",\"WARC-Payload-Digest\":\"sha1:6NBUQDDSLYUX4VIJJWHAM7XPF5TBZMG4\",\"WARC-Block-Digest\":\"sha1:R77RBTWT5SRPREC5547O3MXN4FQR4IED\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2019/CC-MAIN-2019-47/CC-MAIN-2019-47_segments_1573496668716.22_warc_CC-MAIN-20191115222436-20191116010436-00113.warc.gz\"}"}