From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from omta34.uswest2.a.cloudfilter.net (omta34.uswest2.a.cloudfilter.net [35.89.44.33]) by sourceware.org (Postfix) with ESMTPS id D6C963858D1E for ; Thu, 9 Nov 2023 21:24:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D6C963858D1E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=slipbits.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=slipbits.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D6C963858D1E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=35.89.44.33 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699565096; cv=none; b=cfgLXVEaL3iWeK8Vo1MQNspjm9aDnaa6ikVABx5TXfY7lUnBD6ktKCzS3ME7pF0a1eLhP3RUSnDrGJ5255cqwOVxHe/YB0JxW0VcgBcpwicpV8KIMspwEVQ3mmOf6yQHXiNCH/S4BIGmGCeZUXfBMTQU2qThrlGFPIL3SeQYQP4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699565096; c=relaxed/simple; bh=tdmmOv50/m8OZ2AsUWCy+cejMYaCVahAi1DwNeAiKy4=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=Kx0auocCPGRwGPREnaETJOVyifBg48ugbJxzAt4ZAaWq3yuE+kwNVQg6IG21U4pTs2N2Z+wx90S/IGQ7fH/hw+R7lJM2eVwM+ftqydh0yzwxEwF+wtlRP82ycEHwaKvD8f/oRKmalsOwai4RLnWjPXciSejxu3N6hqw57d3dn98= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from eig-obgw-5009a.ext.cloudfilter.net ([10.0.29.176]) by cmsmtp with ESMTPS id 1B0KrdAAU8Hte1CWDrowIU; Thu, 09 Nov 2023 21:24:53 +0000 Received: from box5707.bluehost.com ([162.241.252.110]) by cmsmtp with ESMTPS id 1CWCr1tuK97pz1CWCrHJcu; Thu, 09 Nov 2023 21:24:52 +0000 X-Authority-Analysis: v=2.4 cv=ULDOoQTy c=1 sm=1 tr=0 ts=654d4e24 a=qUfFRToiTI0hwv9vP0yqsA==:117 a=qUfFRToiTI0hwv9vP0yqsA==:17 a=OWjo9vPv0XrRhIrVQ50Ab3nP57M=:19 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=d8ckPdGjgTZL-cOl:21 a=IkcTkHD0fZMA:10 a=BNY50KLci1gA:10 a=Eti_hOKDm4gA:10 a=erTJ_csGAAAA:8 a=i18A1v_PXRdwrigNCNIA:9 a=QEXdDO2ut3YA:10 a=lS4Q9sz1nVb7NiKgUIGt:22 a=5EuxcupID8RaBj3x6S1R:22 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=slipbits.com; s=default; h=Content-Transfer-Encoding:Content-Type: In-Reply-To:From:References:Cc:To:Subject:MIME-Version:Date:Message-ID:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=mZNJNL5TBdmlPeGhUY9D5Su6xt5sbYYCpkUDZBr+QdE=; b=ApdtVUcB/YwwXhecLsUh+UQgxU 61V4W71rR11+d6gtGcvo+azpNDNUO8JdUapXYsFSWd1avAUJN+V80LmSje0Er5A60OJ3+H4/4hrDM g++zmQrBu1nJCH/V8Yn2l/TCyXlZBNvJW/BrA4fYgKieIZxCmaD0B7jzcHNnb5uTA28fY/8aKXGGq Ppf5bciH449vwmhf6J7/GS2GITFvwCt8eoScEIH+iWn2TjGEv89W18lEAq+c2lAyAozRRbXunqXyW JPEzYVNA9J4OkxKohYtEpL22SQbdF8BK0o1wJrS9YPLhQAqijMzDllGxmeZUGx3XNS6CDmKCg+tTp RZ0tPUtw==; Received: from wsip-72-203-216-141.oc.oc.cox.net ([72.203.216.141]:60038 helo=[172.16.226.252]) by box5707.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96.2) (envelope-from ) id 1r1CWB-00449e-34; Thu, 09 Nov 2023 14:24:52 -0700 Message-ID: <7780aa57-1761-475b-9e09-b05d8867ea04@slipbits.com> Date: Thu, 9 Nov 2023 13:24:50 -0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Can you use a function reference passed in a template argument? Content-Language: en-US To: Jonathan Wakely Cc: gcc-help@gcc.gnu.org References: From: Arthur Schwarz In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5707.bluehost.com X-AntiAbuse: Original Domain - gcc.gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - slipbits.com X-BWhitelist: no X-Source-IP: 72.203.216.141 X-Source-L: No X-Exim-ID: 1r1CWB-00449e-34 X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: wsip-72-203-216-141.oc.oc.cox.net ([172.16.226.252]) [72.203.216.141]:60038 X-Source-Auth: home@slipbits.com X-Email-Count: 3 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: c2xpcGJpdHM7c2xpcGJpdHM7Ym94NTcwNy5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfETEzHrwX4DZxCdjxuVgBRhlcjf+l24ZMr+yVPedG/gEBhK1cF//j7GGUtOWqsgOf711+XFMiAR+I50tDZb+Dl4kxbR97EidF40H0wNLHFbkmyAG+Ljy AqW2YbpT7b8JK6OM88oncGmgJJn5Gi3HyHA4+1BnPUe7kXFZXVB3dwlTDhz3rwxskXk/mjjVR5i6u1ezdS4sjtHx7qprUlp9KYg= X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 11/9/2023 1:11 PM, Jonathan Wakely via Gcc-help wrote: > On Thu, 9 Nov 2023 at 20:46, Arthur Schwarz wrote: >> >> Is there any way to use a function passed as an argument to a template >> (example below)? Couldn't the existence of the referenced function be >> established durint instantiation (Stack obj)? I realize that >> just doing analysis of the template that the existence of a referenced >> function can't be determined, but during instantiation it can be validated. > I have no idea what that code is trying to do. You're trying to call a > member function on a _type_ T. As if I knew what I was trying to do. > > And you said you want to call a function passed as an argument ... but > the template argument you pass is a type, not a function. > At the time of object instantiation the 'type' is a class and as a member of this class there is a function. It is resolvable that when a class is used that to satisfy the requirement that the template object is correct, the class must contain the indicated function. If a passed class does not contain the indicated function, then an error can be generated. It looks like the determination of template instantiability is made when the template is 'compiled', and at this time it is not possible to determine that the referenced function, T.fun(), is available. This validation only becomes possible during template instantiation, that is, when template_name is instantiated. To me the question then becomes does the standard require that checking is not deferred until instantiation. >> As a nit, the repeated instances of "../header/" in the error message is >> an annoyance. > That looks like a problem with symlinks or your build system, not gcc's fault. > >> Diagnostic message and code given below. >> >> thanks >> art >> >> ../header/../header/../header/../header/Stack.h: In member function >> β€˜std::string Stack::toString()’: >> ../header/../header/../header/../header/Stack.h:184:46: error: expected >> primary-expression before β€˜.’ token >> 184 | str << setw(3) << s.size() << ": " << T.toString(); >> | ^ >> >> # include >> # include >> >> using namespace std; >> template >> class Stack { >> string toString() { >> stringstream str; >> str << setw(3) << s.size() << ": " << T.toString(); >> return str.str(); >> }; >> }; >>