[LLVMdev] Question about "const"

Stepan Dyatkovskiy STPWORLD at narod.ru
Thu Feb 16 01:55:58 PST 2012


Yup. I'm also inclined to the templates. Thanks.

-Stepan.

16.02.2012, 13:49, "James Molloy" <james.molloy at arm.com>:
> Hi,
>
> I think Chris recently did this with ArrayRef - that might be a good
> template to base your solution on?
>
> Cheers,
>
> James
>
> -----Original Message-----
> From: llvmdev-bounces at cs.uiuc.edu [mailto:llvmdev-bounces at cs.uiuc.edu] On
> Behalf Of Stepan Dyatkovskiy
> Sent: 16 February 2012 06:36
> To: llvmdev at cs.uiuc.edu
> Subject: [LLVMdev] Question about "const"
>
> Hi all. I have a next problem. I need to implement some object that will
> work with both const and "constless" object: Instruction* and const
> Instruction*, for example.
> How to implement it better?
> Currently I see two possible ways:
>
> 1. Templates.
> template <class InstructionTy>
> class InstructionProcessorT {
>   InstructionTy *Inst;
>   InstructionProcessor(InstructionTy *I) : Inst(I) {}
>   //
> };
> typedef InstructionProcessorT<Instruction> InstructionProcessor;
> typedef InstructionProcessorT<const Instruction> ConstInstructionProcessor;
>
> 2. Unions.
> class InstructionProcessor {
>   union {
>     const Instruction *ConstInst;
>     Instruction *Inst;
>   }
>   InstructionProcessor(Instruction *I) : Inst(I) {}
>   InstructionProcessor(const Instruction *I) : ConstInst(I) {}
>
>   void someMethod(); // Will work with Inst.
>   void someMethod() const; // Will work with ConstInst.
> };
>
> Any suggestions?
>
> Thanks!
> -Stepan.
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev



More information about the llvm-dev mailing list