C++ Tutorial => Conversion to function pointer
文章推薦指數: 80 %
This function pointer is in no way reliant on the source lambda closure's existence. It therefore may outlive the lambda closure. This feature is mainly useful ...
DownloadC++(PDF)
C++
GettingstartedwithC++
AwesomeBook
AwesomeCommunity
AwesomeCourse
AwesomeTutorial
AwesomeYouTube
Alignment
ArgumentDependentNameLookup
ArithmiticMetaprogramming
Arrays
AtomicTypes
Attributes
auto
Basicinput/outputinc++
BasicTypeKeywords
Bitfields
BitManipulation
BitOperators
BuildSystems
Cincompatibilities
C++Containers
C++DebuggingandDebug-preventionTools&Techniques
C++function"callbyvalue"vs."callbyreference"
C++Streams
C++11MemoryModel
CallableObjects
Classes/Structures
Clientserverexamples
Commoncompile/linkererrors(GCC)
CompilingandBuilding
ConcurrencyWithOpenMP
ConstCorrectness
constkeyword
Constantclassmemberfunctions
constexpr
CopyElision
CopyingvsAssignment
CuriouslyRecurringTemplatePattern(CRTP)
DataStructuresinC++
Dateandtimeusingheader
decltype
DesignpatternimplementationinC++
Digitseparators
Enumeration
Exceptions
Explicittypeconversions
Expressiontemplates
FileI/O
FloatingPointArithmetic
FlowControl
FoldExpressions
Friendkeyword
FunctionOverloading
FunctionTemplateOverloading
FuturesandPromises
HeaderFiles
Implementation-definedbehavior
Inlinefunctions
Inlinevariables
InternationalizationinC++
Iteration
Iterators
Keywords
Lambdas
Whatisalambdaexpression?
Capturebyreference
Capturebyvalue
Classlambdasandcaptureofthis
Conversiontofunctionpointer
Defaultcapture
Generalizedcapture
Genericlambdas
PortinglambdafunctionstoC++03usingfunctors
Recursivelambdas
Specifyingthereturntype
Usinglambdasforinlineparameterpackunpacking
Layoutofobjecttypes
Linkagespecifications
Literals
Loops
Memorymanagement
Metaprogramming
MoreundefinedbehaviorsinC++
MoveSemantics
mutablekeyword
Mutexes
Namespaces
Non-StaticMemberFunctions
OneDefinitionRule(ODR)
OperatorOverloading
operatorprecedence
Optimization
OptimizationinC++
Overloadresolution
Parameterpacks
PerfectForwarding
PimplIdiom
Pointers
Pointerstomembers
Polymorphism
Preprocessor
Profiling
RAII:ResourceAcquisitionIsInitialization
Randomnumbergeneration
RecursioninC++
RecursiveMutex
RefactoringTechniques
References
Regularexpressions
ResourceManagement
ReturnTypeCovariance
Returningseveralvaluesfromafunction
RTTI:Run-TimeTypeInformation
Scopes
Semaphore
SFINAE(SubstitutionFailureIsNotAnError)
SidebySideComparisonsofclassicC++examplessolvedviaC++vsC++11vsC++14vsC++17
SingletonDesignPattern
SmartPointers
Sorting
SpecialMemberFunctions
StandardLibraryAlgorithms
static_assert
std::any
std::array
std::atomics
std::forward_list
std::function:Towrapanyelementthatiscallable
std::integer_sequence
std::iomanip
std::map
std::optional
std::pair
std::setandstd::multiset
std::string
std::variant
std::vector
Storageclassspecifiers
Streammanipulators
Templates
TheISOC++Standard
TheRuleofThree,Five,AndZero
TheThisPointer
Threadsynchronizationstructures
Threading
Trailingreturntype
typededuction
TypeErasure
TypeInference
TypeKeywords
TypeTraits
Typedefandtypealiases
UndefinedBehavior
Unions
UnitTestinginC++
Unnamedtypes
Unspecifiedbehavior
User-DefinedLiterals
Usingdeclaration
Usingstd::unordered_map
ValueandReferenceSemantics
ValueCategories
VariableDeclarationKeywords
VirtualMemberFunctions
C++
GettingstartedwithC++
AwesomeBook
AwesomeCommunity
AwesomeCourse
AwesomeTutorial
AwesomeYouTube
Alignment
ArgumentDependentNameLookup
ArithmiticMetaprogramming
Arrays
AtomicTypes
Attributes
auto
Basicinput/outputinc++
BasicTypeKeywords
Bitfields
BitManipulation
BitOperators
BuildSystems
Cincompatibilities
C++Containers
C++DebuggingandDebug-preventionTools&Techniques
C++function"callbyvalue"vs."callbyreference"
C++Streams
C++11MemoryModel
CallableObjects
Classes/Structures
Clientserverexamples
Commoncompile/linkererrors(GCC)
CompilingandBuilding
ConcurrencyWithOpenMP
ConstCorrectness
constkeyword
Constantclassmemberfunctions
constexpr
CopyElision
CopyingvsAssignment
CuriouslyRecurringTemplatePattern(CRTP)
DataStructuresinC++
Dateandtimeusingheader
decltype
DesignpatternimplementationinC++
Digitseparators
Enumeration
Exceptions
Explicittypeconversions
Expressiontemplates
FileI/O
FloatingPointArithmetic
FlowControl
FoldExpressions
Friendkeyword
FunctionOverloading
FunctionTemplateOverloading
FuturesandPromises
HeaderFiles
Implementation-definedbehavior
Inlinefunctions
Inlinevariables
InternationalizationinC++
Iteration
Iterators
Keywords
Lambdas
Whatisalambdaexpression?
Capturebyreference
Capturebyvalue
Classlambdasandcaptureofthis
Conversiontofunctionpointer
Defaultcapture
Generalizedcapture
Genericlambdas
PortinglambdafunctionstoC++03usingfunctors
Recursivelambdas
Specifyingthereturntype
Usinglambdasforinlineparameterpackunpacking
Layoutofobjecttypes
Linkagespecifications
Literals
Loops
Memorymanagement
Metaprogramming
MoreundefinedbehaviorsinC++
MoveSemantics
mutablekeyword
Mutexes
Namespaces
Non-StaticMemberFunctions
OneDefinitionRule(ODR)
OperatorOverloading
operatorprecedence
Optimization
OptimizationinC++
Overloadresolution
Parameterpacks
PerfectForwarding
PimplIdiom
Pointers
Pointerstomembers
Polymorphism
Preprocessor
Profiling
RAII:ResourceAcquisitionIsInitialization
Randomnumbergeneration
RecursioninC++
RecursiveMutex
RefactoringTechniques
References
Regularexpressions
ResourceManagement
ReturnTypeCovariance
Returningseveralvaluesfromafunction
RTTI:Run-TimeTypeInformation
Scopes
Semaphore
SFINAE(SubstitutionFailureIsNotAnError)
SidebySideComparisonsofclassicC++examplessolvedviaC++vsC++11vsC++14vsC++17
SingletonDesignPattern
SmartPointers
Sorting
SpecialMemberFunctions
StandardLibraryAlgorithms
static_assert
std::any
std::array
std::atomics
std::forward_list
std::function:Towrapanyelementthatiscallable
std::integer_sequence
std::iomanip
std::map
std::optional
std::pair
std::setandstd::multiset
std::string
std::variant
std::vector
Storageclassspecifiers
Streammanipulators
Templates
TheISOC++Standard
TheRuleofThree,Five,AndZero
TheThisPointer
Threadsynchronizationstructures
Threading
Trailingreturntype
typededuction
TypeErasure
TypeInference
TypeKeywords
TypeTraits
Typedefandtypealiases
UndefinedBehavior
Unions
UnitTestinginC++
Unnamedtypes
Unspecifiedbehavior
User-DefinedLiterals
Usingdeclaration
Usingstd::unordered_map
ValueandReferenceSemantics
ValueCategories
VariableDeclarationKeywords
VirtualMemberFunctions
C++
Lambdas
Conversiontofunctionpointer
Example
Ifalambda'scapturelistisempty,thenthelambdahasanimplicitconversiontoafunctionpointerthattakesthesameargumentsandreturnsthesamereturntype:
autosorter=[](intlhs,intrhs)->bool{returnlhs
延伸文章資訊
- 1Passing C++ captureless lambda as function pointer to C API
- 2Lambda expressions in C++ - Microsoft Docs
- 3c++裡的bind和lambda,為什麼沒辦法變成c-style function ...
在c裡面,function pointer是一個儲存function位置的指標,可以拿來pass一個function讓別人呼叫,通常用來實作callback function。
- 4Behind C++ Lambda Functions - cpp - developer blog
But a lambda function isn't just a pointer. So what is it? Note, we're going to use Clang as an e...
- 5Passing capturing lambda as function pointer - Stack Overflow
A lambda can only be converted to a function pointer if it does not capture, ... I am using this ...